@@ -27,6 +27,81 @@ const fs = require('fs'),
2727 expandHomeDir = require ( 'expand-home-dir' ) ,
2828 wskpropsFile = expandHomeDir ( '~/.wskprops' )
2929
30+ const usage = {
31+ auth : {
32+ toplevel : {
33+ commandPrefix : 'auth' ,
34+ title : 'Authorization Operations' ,
35+ header : 'Commands to switch, list, and remember OpenWhisk authorization keys' ,
36+ related : [ 'host' ]
37+ } ,
38+ list : {
39+ strict : 'list' ,
40+ command : 'list' ,
41+ title : 'List Auth Keys' ,
42+ header : 'List the OpenWhisk namespaces for which you have authorization keys' ,
43+ parents : [ 'auth' ] ,
44+ related : [ 'host set' ]
45+ } ,
46+ switch : {
47+ strict : 'switch' ,
48+ command : 'switch' ,
49+ title : 'Switch Auth Keys' ,
50+ header : 'Switch to use an OpenWhisk namespace, by name' ,
51+ example : 'auth switch <namespace>' ,
52+ required : [ { name : 'namespace' , docs : 'an OpenWhisk namespace' , entity : 'namespace' } ] ,
53+ parents : [ 'auth' ] ,
54+ related : [ 'auth list' , 'host set' ]
55+ } ,
56+ add : {
57+ strict : 'add' ,
58+ command : 'add' ,
59+ title : 'Add Auth Key' ,
60+ header : 'Install an OpenWhisk authorization key' ,
61+ example : 'auth add <auth>' ,
62+ required : [ { name : 'auth' , docs : 'an OpenWhisk authorization key' } ] ,
63+ parents : [ 'auth' ] ,
64+ related : [ 'auth switch' , 'auth list' , 'host set' ]
65+ }
66+ } ,
67+ host : {
68+ toplevel : {
69+ commandPrefix : 'host' ,
70+ title : 'Host Operations' ,
71+ header : 'Commands to switch OpenWhisk API host' ,
72+ related : [ 'auth' ]
73+ } ,
74+ get : {
75+ strict : 'get' ,
76+ command : 'get' ,
77+ commandPrefix : 'host' ,
78+ title : 'Get API Host' ,
79+ header : 'Print the current OpenWhisk API host' ,
80+ example : 'host get' ,
81+ parents : [ 'host' ]
82+ } ,
83+ set : {
84+ strict : 'set' ,
85+ command : 'set' ,
86+ commandPrefix : 'host' ,
87+ title : 'Set API Host' ,
88+ header : 'Change the OpenWhisk API host to a chosen alternative' ,
89+ example : 'host set <which>' ,
90+ nRowsInViewport : 5 ,
91+ oneof : [
92+ { name : 'local' , docs : 'Use a local OpenWhisk installation' } ,
93+ { name : 'us-south' , docs : 'Use the IBM Cloud Dallas installation' } ,
94+ { name : 'eu-gb' , docs : 'Use the IBM Cloud London installation' } ,
95+ { name : 'eu-de' , docs : 'Use the IBM Cloud Frankrut installation' } ,
96+ { name : 'hostname' , docs : 'Use a given hostname or IP address' }
97+ ] ,
98+ parents : [ 'host' ]
99+ }
100+ }
101+ }
102+ usage . auth . toplevel . available = [ usage . auth . add , usage . auth . list , usage . auth . switch ]
103+ usage . host . toplevel . available = [ usage . host . get , usage . host . set ]
104+
30105/**
31106 * The message we will use to inform the user of a auth switch event
32107 *
@@ -142,8 +217,8 @@ const use = (wsk, commandTree) => verb => (_1, _2, _3, _4, _5, _6, argv) => name
142217module . exports = ( commandTree , prequire ) => {
143218 const wsk = prequire ( '/ui/commands/openwhisk-core' )
144219
145- commandTree . subtree ( '/host' , { docs : 'Commands to switch OpenWhisk API host' } )
146- commandTree . subtree ( '/auth' , { docs : 'Commands to switch, list, and remember OpenWhisk authorization keys' } )
220+ commandTree . subtree ( '/host' , { usage : usage . host . toplevel } )
221+ commandTree . subtree ( '/auth' , { usage : usage . auth . toplevel } )
147222
148223 const clicky = ( parent , cmd , exec = repl . pexec ) => {
149224 const dom = document . createElement ( 'span' )
@@ -185,22 +260,22 @@ module.exports = (commandTree, prequire) => {
185260 }
186261 const add = ( _1 , _2 , _3 , _4 , _5 , _6 , argv ) => addFn ( firstArg ( argv , 'add' ) )
187262
188- const listCmd = commandTree . listen ( '/auth/list' , list , { docs : 'List the OpenWhisk authorization keys you have installed' } )
263+ const listCmd = commandTree . listen ( '/auth/list' , list , { usage : usage . auth . list } )
189264 commandTree . synonym ( '/auth/ls' , list , listCmd )
190265
191266 const useFn = use ( wsk , commandTree )
192- const useCmd = commandTree . listen ( '/auth/use ' , useFn ( 'use ' ) , { docs : 'Switch to use an OpenWhisk namespace, by name (hint: try auth ls first)' } )
193- commandTree . synonym ( '/auth/switch' , useFn ( 'switch' ) , useCmd )
267+ const useCmd = commandTree . listen ( '/auth/switch ' , useFn ( 'switch ' ) , { usage : usage . auth . switch } )
268+ // commandTree.synonym('/auth/switch', useFn('switch'), useCmd)
194269 //commandTree.synonym('/auth/use', useFn, useCmd)
195270
196- const addCmd = commandTree . listen ( '/auth/add' , add , { docs : 'Install an OpenWhisk authorization key' } )
197- commandTree . synonym ( '/auth/install' , use , addCmd )
271+ const addCmd = commandTree . listen ( '/auth/add' , add , { usage : usage . auth . add } )
272+ // commandTree.synonym('/auth/install', use, addCmd)
198273
199274 /**
200275 * OpenWhisk API host: get and set commands
201276 *
202277 */
203- commandTree . listen ( '/host/get' , ( ) => wsk . apiHost . get ( ) , { docs : 'Print the current OpenWhisk API host' } )
278+ commandTree . listen ( '/host/get' , ( ) => wsk . apiHost . get ( ) , { usage : usage . host . get } )
204279 commandTree . listen ( '/host/set' ,
205280 ( _1 , _2 , _a , _3 , _4 , _5 , argv_without_options , options ) => {
206281 const argv = slice ( argv_without_options , 'set' )
@@ -241,7 +316,7 @@ module.exports = (commandTree, prequire) => {
241316 host = 'https://192.168.33.13'
242317 ignoreCerts = true
243318 isLocal = true
244- } else if ( host === 'local' ) {
319+ } else if ( host === 'local' || host === 'localhost' ) {
245320 // try a variety of options
246321 const variants = [ 'https://192.168.33.13' , 'http://172.17.0.1:10001' , 'http://192.168.99.100:10001' ]
247322 const request = require ( 'request' )
@@ -324,7 +399,7 @@ module.exports = (commandTree, prequire) => {
324399 }
325400 } ) ) )
326401 } ,
327- { docs : 'Update the current OpenWhisk API host' } )
402+ { usage : usage . host . set } )
328403
329404 return {
330405 add : addFn
0 commit comments