@@ -32,52 +32,69 @@ import (
3232 "github.com/spf13/cobra"
3333)
3434
35+ var pipelinesNamespace string
36+ var pipelinesRuntime string
37+
3538// pipelinesCmd represents the pipelines command
3639var pipelinesCmd = & cobra.Command {
3740 Use : "pipelines" ,
3841 Short : "Collect data for the Codefresh Pipelines Runtime" ,
3942 Long : `Collect data for the Codefresh Pipelines Runtime` ,
4043 Run : func (cmd * cobra.Command , args []string ) {
4144 const RuntimeType = "Codefresh Pipelines Runtime"
45+ var runtimes []map [string ]interface {}
46+ var reSpec map [string ]interface {}
47+
4248 dirPath := fmt .Sprintf ("./codefresh-support-%d" , time .Now ().Unix ())
49+
4350 cfConfig , err := codefresh .GetCodefreshCreds ()
4451 if err != nil {
4552 cmd .PrintErrln ("Error getting Codefresh credentials:" , err )
46- return
4753 }
4854
49- runtimes , err := codefresh .AccountRuntimes (cfConfig )
50- if err != nil {
51- cmd .PrintErrln ("Error getting Codefresh runtimes:" , err )
52- return
53- }
55+ if cfConfig != nil {
56+ if pipelinesRuntime != "" {
57+ reSpec , err = codefresh .SingleRuntime (cfConfig , pipelinesRuntime )
58+ if err != nil {
59+ cmd .PrintErrln ("Error getting Codefresh runtimes:" , err )
60+ }
5461
55- var pipelinesNamespace string
56- var reSpec map [string ]interface {}
62+ } else {
63+ runtimes , err = codefresh .AccountRuntimes (cfConfig )
64+ if err != nil {
65+ cmd .PrintErrln ("Error getting Codefresh runtimes:" , err )
66+ }
5767
58- if len (runtimes ) != 0 {
59- var selection int
60- for index , runtime := range runtimes {
61- cmd .Printf ("%d. %s\n " , index + 1 , runtime ["metadata" ].(map [string ]interface {})["name" ])
62- }
63- for {
64- cmd .Print ("\n Please select the runtime to gather data from (Number): " )
65- _ , err := fmt .Scanf ("%d" , & selection )
66- if err != nil || selection < 1 || selection > len (runtimes ) {
67- cmd .PrintErrln ("Invalid selection. Please enter a number corresponding to one of the listed runtimes." )
68- continue
68+ if len (runtimes ) != 0 {
69+ var selection int
70+ for index , runtime := range runtimes {
71+ cmd .Printf ("%d. %s\n " , index + 1 , runtime ["metadata" ].(map [string ]interface {})["name" ])
72+ }
73+ for {
74+ cmd .Print ("\n Please select the runtime to gather data from (Number): " )
75+ _ , err := fmt .Scanf ("%d" , & selection )
76+ if err != nil || selection < 1 || selection > len (runtimes ) {
77+ cmd .PrintErrln ("Invalid selection. Please enter a number corresponding to one of the listed runtimes." )
78+ continue
79+ }
80+ break
81+
82+ }
83+ reSpec = runtimes [selection - 1 ]
6984 }
70- break
7185
7286 }
73- reSpec = runtimes [selection - 1 ]
74- pipelinesNamespace = reSpec ["runtimeScheduler" ].(map [string ]interface {})["cluster" ].(map [string ]interface {})["namespace" ].(string )
75- } else {
76- cmd .Println ("No runtimes found in Codefresh account." )
77- pipelinesNamespace , err = k8s .SelectNamespace (RuntimeType )
78- if err != nil {
79- cmd .PrintErrf ("error getting Kubernetes namespace: %v" , err )
80- return
87+ }
88+
89+ if pipelinesNamespace == "" {
90+ if reSpec != nil {
91+ pipelinesNamespace = reSpec ["runtimeScheduler" ].(map [string ]interface {})["cluster" ].(map [string ]interface {})["namespace" ].(string )
92+ } else {
93+ pipelinesNamespace , err = k8s .SelectNamespace (RuntimeType )
94+ if err != nil {
95+ cmd .PrintErrf ("error getting Kubernetes namespace: %v" , err )
96+ return
97+ }
8198 }
8299 }
83100
@@ -119,4 +136,6 @@ func init() {
119136 // Cobra supports local flags which will only run when this command
120137 // is called directly, e.g.:
121138 // pipelinesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
139+ pipelinesCmd .Flags ().StringVarP (& pipelinesNamespace , "namespace" , "n" , "" , "The namespace where the Runtime is installed" )
140+ pipelinesCmd .Flags ().StringVarP (& pipelinesRuntime , "runtime" , "re" , "" , "The name of the Pipelines Runtime" )
122141}
0 commit comments