github.com/naphatkrit/deis@v1.12.3/client/parser/keys.go (about) 1 package parser 2 3 import ( 4 "github.com/deis/deis/client/cmd" 5 docopt "github.com/docopt/docopt-go" 6 ) 7 8 // Keys routes key commands to the specific function. 9 func Keys(argv []string) 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) 23 case "keys:add": 24 return keyAdd(argv) 25 case "keys:remove": 26 return keyRemove(argv) 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) 35 } 36 37 PrintUsage() 38 return nil 39 } 40 } 41 42 func keysList(argv []string) 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 cmd.KeysList(results) 66 } 67 68 func keyAdd(argv []string) error { 69 usage := ` 70 Adds SSH keys for the logged in user. 71 72 Usage: deis keys:add [<key>] 73 74 Arguments: 75 <key> 76 a local file path to an SSH public key used to push application code. 77 ` 78 79 args, err := docopt.Parse(usage, argv, true, "", false, true) 80 81 if err != nil { 82 return err 83 } 84 85 key := safeGetValue(args, "<key>") 86 87 return cmd.KeyAdd(key) 88 } 89 90 func keyRemove(argv []string) error { 91 usage := ` 92 Removes an SSH key for the logged in user. 93 94 Usage: deis keys:remove <key> 95 96 Arguments: 97 <key> 98 the SSH public key to revoke source code push access. 99 ` 100 101 args, err := docopt.Parse(usage, argv, true, "", false, true) 102 103 if err != nil { 104 return err 105 } 106 107 key := safeGetValue(args, "<key>") 108 109 return cmd.KeyRemove(key) 110 }