Skip to content

Commit

Permalink
enahnce output in case of cmd create error
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed May 5, 2020
1 parent 5d4943d commit 747b4e8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,26 @@ $ vermin create <image>
To create VM with default settings and provide a script to provision the VM:
$ vermin create <image> </path/to/shell/script.sh>
`,
RunE: func(cmd *cobra.Command, args []string) error {
Run: func(cmd *cobra.Command, args []string) {
imageName := args[0]
var script string
if len(args) > 1 {
script = args[1]
if _, err := os.Stat(script); err != nil {
return err
fmt.Println("file not found", script)
os.Exit(1)
}
}
cpus, _ := cmd.Flags().GetInt("cpus")
mem, _ := cmd.Flags().GetInt("mem")

vmName, err := vms.Create(imageName, script, cpus, mem)
if err != nil {
return err
fmt.Println(err)
os.Exit(1)
}

fmt.Printf("VM created successfuly\n\nTo start using the VM use:\n$ vermin ssh %s\n", vmName)
return nil
},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
Expand Down

0 comments on commit 747b4e8

Please sign in to comment.