MCPcopy Index your code
hub / github.com/smallstep/cli / listAction

Function listAction

command/ssh/list.go:62–106  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

60}
61
62func listAction(ctx *cli.Context) error {
63 if err := errs.MinMaxNumberOfArguments(ctx, 0, 1); err != nil {
64 return err
65 }
66
67 var subject string
68 if ctx.NArg() > 0 {
69 subject = ctx.Args().First()
70 }
71
72 agent, err := sshutil.DialAgent()
73 if err != nil {
74 return err
75 }
76
77 keys, err := agent.List()
78 if err != nil {
79 return errors.Wrap(err, "error listing identities")
80 }
81
82 if len(keys) == 0 {
83 fmt.Println("The agent has no identities.")
84 return nil
85 }
86
87 if ctx.Bool("raw") {
88 for _, k := range keys {
89 if ctx.NArg() == 0 || k.Comment == subject {
90 fmt.Println(k.String())
91 }
92 }
93 } else {
94 for _, k := range keys {
95 if ctx.NArg() == 0 || k.Comment == subject {
96 s, err := libsshutil.FormatFingerprint([]byte(k.String()), libsshutil.DefaultFingerprint)
97 if err != nil {
98 return err
99 }
100 fmt.Println(s)
101 }
102 }
103 }
104
105 return nil
106}

Callers

nothing calls this directly

Calls 2

DialAgentFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…