Skip to content

Commit

Permalink
feat(pkg): create start command
Browse files Browse the repository at this point in the history
This is a duplicate of the create command
  • Loading branch information
mrsimonemms committed Jun 16, 2023
1 parent e0f1c4b commit 716b134
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
50 changes: 26 additions & 24 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,32 @@ import (
var createCmd = &cobra.Command{
Use: "create",
Short: "Create an instance",
RunE: func(cmd *cobra.Command, args []string) error {
options, err := options.FromEnv(false)
if err != nil {
return err
}

ctx := context.Background()
h := hetzner.NewHetzner(options.Token)

req, publicKey, err := h.BuildServerOptions(ctx, options)
if err != nil {
return err
}
if publicKey == nil {
return errors.New("no public key generated")
}

diskSize, err := strconv.Atoi(options.DiskSize)
if err != nil {
return errors.Wrap(err, "parse disk size")
}

return h.Create(ctx, req, diskSize, *publicKey)
},
RunE: createOrStartServer,
}

func createOrStartServer(cmd *cobra.Command, args []string) error {
options, err := options.FromEnv(false)
if err != nil {
return err
}

ctx := context.Background()
h := hetzner.NewHetzner(options.Token)

req, publicKey, err := h.BuildServerOptions(ctx, options)
if err != nil {
return err
}
if publicKey == nil {
return errors.New("no public key generated")
}

diskSize, err := strconv.Atoi(options.DiskSize)
if err != nil {
return errors.Wrap(err, "parse disk size")
}

return h.Create(ctx, req, diskSize, *publicKey)
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
var startCmd = &cobra.Command{
Use: "start",
Short: "Start an instance",
RunE: createOrStartServer,
}

func init() {
Expand Down

0 comments on commit 716b134

Please sign in to comment.