From 1595eb83b93322ba1ada9bbbb4e1a91d76ce19e6 Mon Sep 17 00:00:00 2001 From: bohendo Date: Fri, 26 Jul 2024 16:23:02 -0400 Subject: [PATCH] use flag to get launch config path instead of positional param --- cmd/cloudexec/cancel.go | 2 +- cmd/cloudexec/main.go | 21 +++++++++++---------- justfile | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/cloudexec/cancel.go b/cmd/cloudexec/cancel.go index b095219..d256291 100644 --- a/cmd/cloudexec/cancel.go +++ b/cmd/cloudexec/cancel.go @@ -13,7 +13,7 @@ import ( func CancelJob(config config.Config, existingState *state.State, job *state.Job, force bool) error { if job.Status != state.Provisioning && job.Status != state.Running { log.Info("Job %v is not running, it is %s", job.ID, job.Status) - return nil + return nil } log.Warn("Destroying droplet %s associated with job %v: IP=%v | CreatedAt=%s", job.Droplet.Name, job.ID, job.Droplet.IP, job.Droplet.Created) if !force { // Ask for confirmation before cleaning this job if no force flag diff --git a/cmd/cloudexec/main.go b/cmd/cloudexec/main.go index 5947c13..14254e6 100644 --- a/cmd/cloudexec/main.go +++ b/cmd/cloudexec/main.go @@ -14,11 +14,10 @@ import ( ) var ( - Version = "dev" - Commit = "none" - Date = "unknown" - ConfigFilePath = fmt.Sprintf("%s/.config/cloudexec/config.toml", os.Getenv("HOME")) - LaunchConfigFilePath = "./cloudexec.toml" + Version = "dev" + Commit = "none" + Date = "unknown" + ConfigFilePath = fmt.Sprintf("%s/.config/cloudexec/config.toml", os.Getenv("HOME")) ) func main() { @@ -90,6 +89,7 @@ func main() { Flags: []cli.Flag{ &cli.StringFlag{ Name: "config", + Value: "./cloudexec.toml", // default config filepath Usage: "cloudexec.toml file path", }, &cli.StringFlag{ @@ -109,15 +109,16 @@ func main() { return configErr } // Check if a local cloudexec.toml exists - if _, err := os.Stat(LaunchConfigFilePath); os.IsNotExist(err) { + launchConfigFilePath := c.String("config") + if _, err := os.Stat(launchConfigFilePath); os.IsNotExist(err) { // Check if the path to a launch config is provided if c.Args().Len() < 1 { - return fmt.Errorf("please provide a path to a cloudexec.toml file or create one in the current directory") + return fmt.Errorf("please create cloudexec.toml with 'cloudexec init' or use the '--config' flag to provide a path to your custom launch config file") } - LaunchConfigFilePath = c.Args().Get(0) + launchConfigFilePath = c.String("config") } // Load the launch configuration - lc, err := LoadLaunchConfig(LaunchConfigFilePath) + lc, err := LoadLaunchConfig(launchConfigFilePath) if err != nil { return err } @@ -129,7 +130,7 @@ func main() { return err } err = Launch(config, dropletSize, dropletRegion, lc) - return err + return err }, }, diff --git a/justfile b/justfile index 3b055af..78f07f5 100644 --- a/justfile +++ b/justfile @@ -5,7 +5,7 @@ fmt: go fmt pkg/ssh/*.go go fmt pkg/state/*.go -trunk: +trunk: fmt trunk fmt trunk check