Skip to content

Commit 8bf3f55

Browse files
committed
boilerplate tip cmd
1 parent e093d23 commit 8bf3f55

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pkg/cmd/root/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
releaseCmd "github.com/cli/cli/pkg/cmd/release"
2020
repoCmd "github.com/cli/cli/pkg/cmd/repo"
2121
creditsCmd "github.com/cli/cli/pkg/cmd/repo/credits"
22+
tipCmd "github.com/cli/cli/pkg/cmd/tip"
2223
versionCmd "github.com/cli/cli/pkg/cmd/version"
2324
"github.com/cli/cli/pkg/cmdutil"
2425
"github.com/spf13/cobra"
@@ -68,6 +69,7 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command {
6869
cmd.AddCommand(creditsCmd.NewCmdCredits(f, nil))
6970
cmd.AddCommand(gistCmd.NewCmdGist(f))
7071
cmd.AddCommand(completionCmd.NewCmdCompletion(f.IOStreams))
72+
cmd.AddCommand(tipCmd.NewCmdTip(f, nil))
7173

7274
// the `api` command should not inherit any extra HTTP headers
7375
bareHTTPCmdFactory := *f

pkg/cmd/tip/tip.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package tip
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/cli/cli/pkg/cmdutil"
7+
"github.com/cli/cli/pkg/iostreams"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
type TipOptions struct {
12+
IO *iostreams.IOStreams
13+
14+
Character string
15+
}
16+
17+
func NewCmdTip(f *cmdutil.Factory, runF func(*TipOptions) error) *cobra.Command {
18+
opts := &TipOptions{
19+
IO: f.IOStreams,
20+
}
21+
22+
cmd := &cobra.Command{
23+
Use: "tip",
24+
Short: "get a random tip about using gh",
25+
Args: cobra.NoArgs,
26+
RunE: func(cmd *cobra.Command, args []string) error {
27+
if runF != nil {
28+
return runF(opts)
29+
}
30+
return tipRun(opts)
31+
},
32+
}
33+
34+
cmd.Flags().StringVarP(&opts.Character, "character", "c", "clippy", "What helpful animated character you'd like a tip from")
35+
36+
return cmd
37+
}
38+
39+
func tipRun(opts *TipOptions) error {
40+
fmt.Println("hey")
41+
return nil
42+
}

0 commit comments

Comments
 (0)