Skip to content

Commit

Permalink
Use positional args
Browse files Browse the repository at this point in the history
  • Loading branch information
asaha2 committed Nov 15, 2024
1 parent cc7493b commit 312d9d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
36 changes: 18 additions & 18 deletions commands/droplet_autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ You can use droplet-autoscale to perform CRUD operations on a Droplet Autoscale
}
cmdDropletAutoscaleCreate := CmdBuilder(cmd, RunDropletAutoscaleCreate, "create", "Create a new Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscalePools{}))

cmdDropletAutoscaleUpdate := CmdBuilder(cmd, RunDropletAutoscaleUpdate, "update", "Update an active Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscalePools{}))
AddStringFlag(cmdDropletAutoscaleUpdate, doctl.ArgAutoscaleID, "", "", "ID of the Droplet autoscale pool", requiredOpt())
cmdDropletAutoscaleUpdate := CmdBuilder(cmd, RunDropletAutoscaleUpdate, "update <autoscale-pool-id>", "Update an active Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscalePools{}))

for _, c := range []*Command{
cmdDropletAutoscaleCreate,
Expand All @@ -62,23 +61,18 @@ You can use droplet-autoscale to perform CRUD operations on a Droplet Autoscale
AddStringFlag(c, doctl.ArgUserData, "", "", "Droplet user data")
}

cmdDropletAutoscaleGet := CmdBuilder(cmd, RunDropletAutoscaleGet, "get", "Get an active Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscalePools{}))
AddStringFlag(cmdDropletAutoscaleGet, doctl.ArgAutoscaleID, "", "", "ID of the Droplet autoscale pool", requiredOpt())
CmdBuilder(cmd, RunDropletAutoscaleGet, "get <autoscale-pool-id>", "Get an active Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscalePools{}))

CmdBuilder(cmd, RunDropletAutoscaleList, "list", "List all active Droplet autoscale pools", "", Writer, displayerType(&displayers.DropletAutoscalePools{}), aliasOpt("ls"))

cmdDropletAutoscaleListMembers := CmdBuilder(cmd, RunDropletAutoscaleListMembers, "list-members", "List all members of a Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscaleResources{}))
AddStringFlag(cmdDropletAutoscaleListMembers, doctl.ArgAutoscaleID, "", "", "ID of the Droplet autoscale pool", requiredOpt())
CmdBuilder(cmd, RunDropletAutoscaleListMembers, "list-members <autoscale-pool-id>", "List all members of a Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscaleResources{}))

cmdDropletAutoscaleListHistory := CmdBuilder(cmd, RunDropletAutoscaleListHistory, "list-history", "List all history events for a Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscaleHistoryEvents{}))
AddStringFlag(cmdDropletAutoscaleListHistory, doctl.ArgAutoscaleID, "", "", "ID of the Droplet autoscale pool", requiredOpt())
CmdBuilder(cmd, RunDropletAutoscaleListHistory, "list-history <autoscale-pool-id>", "List all history events for a Droplet autoscale pool", "", Writer, displayerType(&displayers.DropletAutoscaleHistoryEvents{}))

cmdDropletAutoscaleDelete := CmdBuilder(cmd, RunDropletAutoscaleDelete, "delete", "Delete an active Droplet autoscale pool", "", Writer, aliasOpt("d", "rm"))
AddStringFlag(cmdDropletAutoscaleDelete, doctl.ArgAutoscaleID, "", "", "ID of the Droplet autoscale pool", requiredOpt())
cmdDropletAutoscaleDelete := CmdBuilder(cmd, RunDropletAutoscaleDelete, "delete <autoscale-pool-id>", "Delete an active Droplet autoscale pool", "", Writer, aliasOpt("d", "rm"))
AddBoolFlag(cmdDropletAutoscaleDelete, doctl.ArgForce, "", false, "Force delete without a confirmation prompt")

cmdDropletAutoscaleDeleteDangerous := CmdBuilder(cmd, RunDropletAutoscaleDeleteDangerous, "delete-dangerous", "Delete an active Droplet autoscale pool and all its members", "", Writer)
AddStringFlag(cmdDropletAutoscaleDeleteDangerous, doctl.ArgAutoscaleID, "", "", "ID of the Droplet autoscale pool", requiredOpt())
cmdDropletAutoscaleDeleteDangerous := CmdBuilder(cmd, RunDropletAutoscaleDeleteDangerous, "delete-dangerous <autoscale-pool-id>", "Delete an active Droplet autoscale pool and all its members", "", Writer)
AddBoolFlag(cmdDropletAutoscaleDeleteDangerous, doctl.ArgForce, "", false, "Force delete without a confirmation prompt")

return cmd
Expand Down Expand Up @@ -261,10 +255,11 @@ func RunDropletAutoscaleCreate(c *CmdConfig) error {

// RunDropletAutoscaleUpdate updates an autoscale pool
func RunDropletAutoscaleUpdate(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, doctl.ArgAutoscaleID)
err := ensureOneArg(c)
if err != nil {
return err
}
id := c.Args[0]
updateReq := new(godo.DropletAutoscalePoolRequest)
updateReq.Config = new(godo.DropletAutoscaleConfiguration)
updateReq.DropletTemplate = new(godo.DropletAutoscaleResourceTemplate)
Expand All @@ -281,10 +276,11 @@ func RunDropletAutoscaleUpdate(c *CmdConfig) error {

// RunDropletAutoscaleGet retrieves an autoscale pool
func RunDropletAutoscaleGet(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, doctl.ArgAutoscaleID)
err := ensureOneArg(c)
if err != nil {
return err
}
id := c.Args[0]
pool, err := c.DropletAutoscale().Get(id)
if err != nil {
return err
Expand All @@ -305,10 +301,11 @@ func RunDropletAutoscaleList(c *CmdConfig) error {

// RunDropletAutoscaleListMembers lists autoscale pool members
func RunDropletAutoscaleListMembers(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, doctl.ArgAutoscaleID)
err := ensureOneArg(c)
if err != nil {
return err
}
id := c.Args[0]
members, err := c.DropletAutoscale().ListMembers(id)
if err != nil {
return err
Expand All @@ -319,10 +316,11 @@ func RunDropletAutoscaleListMembers(c *CmdConfig) error {

// RunDropletAutoscaleListHistory lists autoscale pool history events
func RunDropletAutoscaleListHistory(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, doctl.ArgAutoscaleID)
err := ensureOneArg(c)
if err != nil {
return err
}
id := c.Args[0]
history, err := c.DropletAutoscale().ListHistory(id)
if err != nil {
return err
Expand All @@ -333,10 +331,11 @@ func RunDropletAutoscaleListHistory(c *CmdConfig) error {

// RunDropletAutoscaleDelete deletes an autoscale pool
func RunDropletAutoscaleDelete(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, doctl.ArgAutoscaleID)
err := ensureOneArg(c)
if err != nil {
return err
}
id := c.Args[0]
force, err := c.Doit.GetBool(c.NS, doctl.ArgForce)
if err != nil {
return err
Expand All @@ -353,10 +352,11 @@ func RunDropletAutoscaleDelete(c *CmdConfig) error {

// RunDropletAutoscaleDeleteDangerous deletes an autoscale pool and all underlying members
func RunDropletAutoscaleDeleteDangerous(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, doctl.ArgAutoscaleID)
err := ensureOneArg(c)
if err != nil {
return err
}
id := c.Args[0]
force, err := c.Doit.GetBool(c.NS, doctl.ArgForce)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions commands/droplet_autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestDropletAutoscaleUpdate(t *testing.T) {
}

tm.dropletAutoscale.EXPECT().Update(poolID, &updateReq).Return(testAutoscalePools[0], nil)
c.Doit.Set(c.NS, doctl.ArgAutoscaleID, poolID)
c.Args = append(c.Args, poolID)

c.Doit.Set(c.NS, doctl.ArgAutoscaleName, "test-droplet-autoscale-pool-01")
c.Doit.Set(c.NS, doctl.ArgAutoscaleTargetInstances, "3")
Expand All @@ -161,7 +161,7 @@ func TestDropletAutoscaleGet(t *testing.T) {
withTestClient(t, func(c *CmdConfig, tm *tcMocks) {
poolID := "51154959-e07b-4093-98fb-828590ecc76d"
tm.dropletAutoscale.EXPECT().Get(poolID).Return(testAutoscalePools[0], nil)
c.Doit.Set(c.NS, doctl.ArgAutoscaleID, poolID)
c.Args = append(c.Args, poolID)

err := RunDropletAutoscaleGet(c)
assert.NoError(t, err)
Expand All @@ -181,7 +181,7 @@ func TestDropletAutoscaleListMembers(t *testing.T) {
withTestClient(t, func(c *CmdConfig, tm *tcMocks) {
poolID := "51154959-e07b-4093-98fb-828590ecc76d"
tm.dropletAutoscale.EXPECT().ListMembers(poolID).Return(testAutoscaleMembers, nil)
c.Doit.Set(c.NS, doctl.ArgAutoscaleID, poolID)
c.Args = append(c.Args, poolID)

err := RunDropletAutoscaleListMembers(c)
assert.NoError(t, err)
Expand All @@ -192,7 +192,7 @@ func TestDropletAutoscaleListHistory(t *testing.T) {
withTestClient(t, func(c *CmdConfig, tm *tcMocks) {
poolID := "51154959-e07b-4093-98fb-828590ecc76d"
tm.dropletAutoscale.EXPECT().ListHistory(poolID).Return(testAutoscaleHistory, nil)
c.Doit.Set(c.NS, doctl.ArgAutoscaleID, poolID)
c.Args = append(c.Args, poolID)

err := RunDropletAutoscaleListHistory(c)
assert.NoError(t, err)
Expand All @@ -203,7 +203,7 @@ func TestDropletAutoscaleDelete(t *testing.T) {
withTestClient(t, func(c *CmdConfig, tm *tcMocks) {
poolID := "51154959-e07b-4093-98fb-828590ecc76d"
tm.dropletAutoscale.EXPECT().Delete(poolID).Return(nil)
c.Doit.Set(c.NS, doctl.ArgAutoscaleID, poolID)
c.Args = append(c.Args, poolID)
c.Doit.Set(c.NS, doctl.ArgForce, "true")

err := RunDropletAutoscaleDelete(c)
Expand All @@ -215,7 +215,7 @@ func TestDropletAutoscaleDeleteDangerous(t *testing.T) {
withTestClient(t, func(c *CmdConfig, tm *tcMocks) {
poolID := "51154959-e07b-4093-98fb-828590ecc76d"
tm.dropletAutoscale.EXPECT().DeleteDangerous(poolID).Return(nil)
c.Doit.Set(c.NS, doctl.ArgAutoscaleID, poolID)
c.Args = append(c.Args, poolID)
c.Doit.Set(c.NS, doctl.ArgForce, "true")

err := RunDropletAutoscaleDeleteDangerous(c)
Expand Down

0 comments on commit 312d9d6

Please sign in to comment.