MCPcopy
hub / github.com/cli/cli / NewCmdAdd

Function NewCmdAdd

pkg/cmd/gpg-key/add/add.go:26–56  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*AddOptions) error)

Source from the content-addressed store, hash-verified

24}
25
26func NewCmdAdd(f *cmdutil.Factory, runF func(*AddOptions) error) *cobra.Command {
27 opts := &AddOptions{
28 HTTPClient: f.HttpClient,
29 Config: f.Config,
30 IO: f.IOStreams,
31 }
32
33 cmd := &cobra.Command{
34 Use: "add [<key-file>]",
35 Short: "Add a GPG key to your GitHub account",
36 Args: cobra.MaximumNArgs(1),
37 RunE: func(cmd *cobra.Command, args []string) error {
38 if len(args) == 0 {
39 if opts.IO.IsStdoutTTY() && opts.IO.IsStdinTTY() {
40 return cmdutil.FlagErrorf("GPG key file missing")
41 }
42 opts.KeyFile = "-"
43 } else {
44 opts.KeyFile = args[0]
45 }
46
47 if runF != nil {
48 return runF(opts)
49 }
50 return runAdd(opts)
51 },
52 }
53
54 cmd.Flags().StringVarP(&opts.Title, "title", "t", "", "Title for the new key")
55 return cmd
56}
57
58func runAdd(opts *AddOptions) error {
59 httpClient, err := opts.HTTPClient()

Callers

nothing calls this directly

Calls 4

FlagErrorfFunction · 0.92
IsStdoutTTYMethod · 0.80
IsStdinTTYMethod · 0.80
runAddFunction · 0.70

Tested by

no test coverage detected