From 3341fe8e116bc84fc59eeee7e01a78055400ddab Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Fri, 15 Jun 2018 16:12:35 -0700 Subject: [PATCH] Adding fetch jobs command. Currently only takes into account the role. --- cmd/fetch.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cmd/fetch.go b/cmd/fetch.go index a7c6bba..8cf6ba7 100644 --- a/cmd/fetch.go +++ b/cmd/fetch.go @@ -22,6 +22,10 @@ func init() { // Fetch Leader fetchCmd.AddCommand(leaderCmd) + + // Fetch jobs + fetchCmd.AddCommand(fetchJobsCmd) + fetchJobsCmd.Flags().StringVarP(&role, "role", "r", "", "Aurora Role") } var fetchCmd = &cobra.Command{ @@ -45,6 +49,13 @@ var leaderCmd = &cobra.Command{ Run: fetchLeader, } +var fetchJobsCmd = &cobra.Command{ + Use: "jobs", + Short: "Fetch a list of task Aurora running under a role.", + Long: `To be written.`, + Run: fetchJobs, +} + func fetchTasks(cmd *cobra.Command, args []string) { fmt.Printf("Fetching job configuration for [%s/%s/%s] \n", env, role, name) @@ -79,3 +90,30 @@ func fetchLeader(cmd *cobra.Command, args []string) { fmt.Print(url) } + +// TODO: Expand this to be able to filter by job name and environment. +func fetchJobs(cmd *cobra.Command, args []string) { + fmt.Printf("Fetching tasks under role: %s \n", role) + + if role == "" { + fmt.Println("Role must be specified.") + os.Exit(1) + } + + if role == "*" { + fmt.Println("Warning: This is an expensive operation.") + role = "" + } + + _, result, err := client.GetJobs(role) + + if err != nil { + fmt.Print("error: %+v\n", err.Error()) + os.Exit(1) + } + + for jobConfig, _ := range result.GetConfigs() { + fmt.Println(jobConfig) + } + +}