github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/keys.go (about) 1 package parser 2 3 import ( 4 "github.com/teamhephy/workflow-cli/cmd" 5 docopt "github.com/docopt/docopt-go" 6 ) 7 8 // Keys routes key commands to the specific function. 9 func Keys(argv []string, cmdr cmd.Commander) error { 10 usage := ` 11 Valid commands for SSH keys: 12 13 keys:list list SSH keys for the logged in user 14 keys:add add an SSH key 15 keys:remove remove an SSH key 16 17 Use 'deis help [command]' to learn more. 18 ` 19 20 switch argv[0] { 21 case "keys:list": 22 return keysList(argv, cmdr) 23 case "keys:add": 24 return keyAdd(argv, cmdr) 25 case "keys:remove": 26 return keyRemove(argv, cmdr) 27 default: 28 if printHelp(argv, usage) { 29 return nil 30 } 31 32 if argv[0] == "keys" { 33 argv[0] = "keys:list" 34 return keysList(argv, cmdr) 35 } 36 37 PrintUsage(cmdr) 38 return nil 39 } 40 } 41 42 func keysList(argv []string, cmdr cmd.Commander) error { 43 usage := ` 44 Lists SSH keys for the logged in user. 45 46 Usage: deis keys:list [options] 47 48 Options: 49 -l --limit=<num> 50 the maximum number of results to display, defaults to config setting 51 ` 52 53 args, err := docopt.Parse(usage, argv, true, "", false, true) 54 55 if err != nil { 56 return err 57 } 58 59 results, err := responseLimit(safeGetValue(args, "--limit")) 60 61 if err != nil { 62 return err 63 } 64 65 return cmdr.KeysList(results) 66 } 67 68 func keyAdd(argv []string, cmdr cmd.Commander) error { 69 usage := ` 70 Adds SSH keys for the logged in user. 71 72 Usage: deis keys:add [<name>] [<key>] 73 74 <name> and <key> can be used in either order and are both optional 75 76 Arguments: 77 <name> 78 name of the SSH key 79 <key> 80 a local file path to an SSH public key used to push application code. 81 ` 82 83 args, err := docopt.Parse(usage, argv, true, "", false, true) 84 if err != nil { 85 return err 86 } 87 88 return cmdr.KeyAdd(safeGetValue(args, "<name>"), safeGetValue(args, "<key>")) 89 } 90 91 func keyRemove(argv []string, cmdr cmd.Commander) error { 92 usage := ` 93 Removes an SSH key for the logged in user. 94 95 Usage: deis keys:remove <key> 96 97 Arguments: 98 <key> 99 the SSH public key to revoke source code push access. 100 ` 101 102 args, err := docopt.Parse(usage, argv, true, "", false, true) 103 if err != nil { 104 return err 105 } 106 107 return cmdr.KeyRemove(safeGetValue(args, "<key>")) 108 }