From 3554984238487f0fb17b3e2a484428655e2ba5eb Mon Sep 17 00:00:00 2001 From: Lorenzo Setale Date: Sun, 15 Nov 2020 21:14:34 +0100 Subject: [PATCH] adds aliases Signed-off-by: Lorenzo Setale --- cmd/pack.go | 5 +++-- cmd/plan.go | 9 +++++---- cmd/run.go | 9 +++++---- cmd/unpack.go | 9 +++++---- conn/client.go | 2 +- conn/client_job.go | 11 ++++++++--- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/cmd/pack.go b/cmd/pack.go index bee05c0..33f1d52 100644 --- a/cmd/pack.go +++ b/cmd/pack.go @@ -12,8 +12,9 @@ import ( // packCmd represents the pack command var packCmd = &cobra.Command{ - Use: "pack [path]", - Short: "Build a Backpack file (pack) from a directory/template", + Use: "pack [path]", + Aliases: []string{"package"}, + Short: "Build a Backpack file (pack) from a directory/template", Long: `Generate a Backpack file (pack) from a directory containing the various jobs, metadata and documentation. diff --git a/cmd/plan.go b/cmd/plan.go index 0983134..fcedc63 100644 --- a/cmd/plan.go +++ b/cmd/plan.go @@ -15,9 +15,10 @@ import ( // planCmd represents the run command var planCmd = &cobra.Command{ - Use: "plan [path]", - Args: cobra.ExactArgs(1), - Short: "Plan and check the changes before running a pack", + Use: "plan [path]", + Aliases: []string{"diff", "dry-run"}, + Args: cobra.ExactArgs(1), + Short: "Plan and check the changes before running a pack", Long: `It allows you to plan ahead before running/registering jobs. It is useful when combined with existing jobs to validate changes. By default the output shows you a brief summary of changes, but if you want to see the @@ -81,7 +82,7 @@ func planRun(cmd *cobra.Command, args []string) { } // For each job file perform the plan! 🚀 for name, hcl := range bts { - job, err := client.GetJob(string(hcl)) + job, err := client.GetJobFromCode(string(hcl)) if err != nil { log.Fatalf("Error obtaining job %s: %s", name, err) } diff --git a/cmd/run.go b/cmd/run.go index ae37312..7695123 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -13,9 +13,10 @@ import ( // runCmd represents the run command var runCmd = &cobra.Command{ - Use: "run [path]", - Args: cobra.ExactArgs(1), - Short: "Starts the jobs of a pack", + Use: "run [path]", + Aliases: []string{"start", "install"}, + Args: cobra.ExactArgs(1), + Short: "Starts the jobs of a pack", Long: `It allows to run different jobs specified in the pack. It accepts one argument that is the path or URL of the file, but if the option --unpacked (or -u is) passed it consider the first argument as the path of an @@ -62,7 +63,7 @@ func runRun(cmd *cobra.Command, args []string) { // then store the job ID in the backpack to show it afterwards. jIDs := map[string]string{} for name, hcl := range bts { - job, err := client.GetJob(string(hcl)) + job, err := client.GetJobFromCode(string(hcl)) if err != nil { log.Fatalf("Error obtaining job %s: %s", name, err) } diff --git a/cmd/unpack.go b/cmd/unpack.go index 2a0ddb7..2d009e1 100644 --- a/cmd/unpack.go +++ b/cmd/unpack.go @@ -12,10 +12,11 @@ import ( // unpackCmd represents the unpack command var unpackCmd = &cobra.Command{ - Use: "unpack [file.backpack]", - Args: cobra.ExactArgs(1), - Run: unpackRun, - Short: "Opens a pack file to explore content", + Use: "unpack [file.backpack]", + Aliases: []string{"pull"}, + Args: cobra.ExactArgs(1), + Run: unpackRun, + Short: "Opens a pack file to explore content", Long: `Explodes/Open the pack inside a directory. This is useful to edit a pack, inspecting it or seeing default values... or if you are looking for something inside it and you know it is at the bottom of the backpack! diff --git a/conn/client.go b/conn/client.go index 7f0bfe6..8c46cd0 100644 --- a/conn/client.go +++ b/conn/client.go @@ -24,7 +24,7 @@ func NewClient() (co *Client, err error) { // IsValid that is the question! func (co *Client) IsValid(code string) bool { - job, err := co.GetJob(code) + job, err := co.GetJobFromCode(code) if err != nil { return false } diff --git a/conn/client_job.go b/conn/client_job.go index 982184e..3b6dfcc 100644 --- a/conn/client_job.go +++ b/conn/client_job.go @@ -4,7 +4,12 @@ import ( "github.com/hashicorp/nomad/api" ) -// Run is parsing the HCL code and registering the Job into Nomad -func (co *Client) GetJob(code string) (*api.Job, error) { - return co.c.Jobs().ParseHCL(code, true) +// GetJobFromCode is parsing the HCL code and providing a api.Job{} pointer +func (co *Client) GetJobFromCode(code string) (*api.Job, error) { + return co.jobs.ParseHCL(code, true) +} + +func (co *Client) GetJobStatus(jobId string) (j *api.Job, err error) { + j, _, err = co.jobs.Info(jobId, nil) + return }