Skip to content

Commit

Permalink
use flag to get launch config path instead of positional param
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Jul 26, 2024
1 parent 8bc0dd4 commit 1595eb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/cloudexec/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions cmd/cloudexec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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{
Expand All @@ -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
}
Expand All @@ -129,7 +130,7 @@ func main() {
return err
}
err = Launch(config, dropletSize, dropletRegion, lc)
return err
return err
},
},

Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fmt:
go fmt pkg/ssh/*.go
go fmt pkg/state/*.go

trunk:
trunk: fmt
trunk fmt
trunk check

Expand Down

0 comments on commit 1595eb8

Please sign in to comment.