Adding fetch jobs command. Currently only takes into account the role.

This commit is contained in:
Renan DelValle 2018-06-15 16:12:35 -07:00
parent 09469f3216
commit 3341fe8e11
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9

View file

@ -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)
}
}