Skip to content

Commit

Permalink
Add plans metal list command and update some helptext on plans (#240
Browse files Browse the repository at this point in the history
)
  • Loading branch information
optik-aper authored Mar 30, 2022
1 parent 74a9fee commit 477c30b
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,38 @@ import (
"github.com/vultr/vultr-cli/v2/cmd/printer"
)

var (
plansLong = `Get commands available to plans`
plansExample = `
#Full example
vultr-cli plans
`

plansListLong = `Get all Vultr plans`
plansListExample = `
#Full example
vultr-cli plans list
#Full example with paging
vultr-cli plans list --type=vc2 --per-page=5 --cursor="bmV4dF9fdmMyLTJjLTRnYg=="
#Shortened with aliased commands
vultr-cli p l
`
)

// Plans represents the plans command
func Plans() *cobra.Command {
planCmd := &cobra.Command{
Use: "plans",
Short: "get information about Vultr plans",
Aliases: []string{"p"},
Long: plansLong,
Example: plansExample,
}

planCmd.AddCommand(planList)
planCmd.AddCommand(PlansMetal())

planList.Flags().StringP("type", "t", "", "(optional) The type of plans to return. Possible values: 'bare-metal', 'vc2', 'vdc2', 'ssd', 'dedicated'. Defaults to all VPS plans.")

Expand All @@ -45,6 +68,8 @@ var planList = &cobra.Command{
Use: "list",
Short: "list plans",
Aliases: []string{"l"},
Long: plansListLong,
Example: plansListExample,
Run: func(cmd *cobra.Command, args []string) {
planType, _ := cmd.Flags().GetString("type")
options := getPaging(cmd)
Expand Down
81 changes: 81 additions & 0 deletions cmd/plansMetal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright © 2019 The Vultr-cli Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/vultr/vultr-cli/v2/cmd/printer"
)

var (
plansMetalLong = `Get commands available to metal`
plansMetalExample = `
#Full example
vultr-cli plans metal
`

plansMetalListLong = `Get all Vultr bare metal plans`
plansMetalListExample = `
#Full example
vultr-cli plans metal list
#Full example with paging
vultr-cli plans metal list --per-page=10 --cursor="bmV4dF9fQU1T"
#Shortened with aliased commands
vultr-cli p m l
`
)

// PlansMetal represents the metal sub command
func PlansMetal() *cobra.Command {
planMetalCmd := &cobra.Command{
Use: "metal",
Aliases: []string{"m"},
Short: "metal is used to access bare metal commands",
Long: plansMetalLong,
Example: plansMetalExample,
}

planMetalCmd.AddCommand(metalList)

metalList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
metalList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")

return planMetalCmd
}

var metalList = &cobra.Command{
Use: "list",
Short: "list bare-metal plans",
Long: plansMetalListLong,
Example: plansMetalListExample,
Aliases: []string{"l"},
Run: func(cmd *cobra.Command, args []string) {
options := getPaging(cmd)
list, meta, err := client.Plan.ListBareMetal(context.TODO(), options)

if err != nil {
fmt.Printf("error getting bare metal plan list : %v\n", err)
os.Exit(1)
}

printer.PlanBareMetal(list, meta)
},
}

0 comments on commit 477c30b

Please sign in to comment.