MCPcopy Index your code
hub / github.com/cli/cli / NewCmdAdd

Function NewCmdAdd

pkg/cmd/ssh-key/add/add.go:26–58  ·  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 an SSH 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("public 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 typeEnums := []string{shared.AuthenticationKey, shared.SigningKey}
55 cmdutil.StringEnumFlag(cmd, &opts.Type, "type", "", shared.AuthenticationKey, typeEnums, "Type of the ssh key")
56 cmd.Flags().StringVarP(&opts.Title, "title", "t", "", "Title for the new key")
57 return cmd
58}
59
60func runAdd(opts *AddOptions) error {
61 httpClient, err := opts.HTTPClient()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected