@@ -23,7 +23,7 @@ import (
2323 "os"
2424
2525 "github.com/fatih/color"
26- "github.com/mitchellh/go-homedir"
26+ homedir "github.com/mitchellh/go-homedir"
2727 "github.com/spf13/cobra"
2828
2929 "github.com/apache/incubator-openwhisk-cli/wski18n"
@@ -53,6 +53,18 @@ const DefaultAPIBuildNo string = ""
5353const DefaultNamespace string = "_"
5454const DefaultPropsFile string = "~/.wskprops"
5555
56+ const (
57+ propDisplayCert = "client cert"
58+ propDisplayKey = "Client key"
59+ propDisplayAuth = "whisk auth"
60+ propDisplayAPIHost = "whisk API host"
61+ propDisplayAPIVersion = "whisk API version"
62+ propDisplayNamespace = "whisk namespace"
63+ propDisplayCLIVersion = "whisk CLI version"
64+ propDisplayAPIBuild = "whisk API build"
65+ propDisplayAPIBuildNo = "whisk API build number"
66+ )
67+
5668var propertyCmd = & cobra.Command {
5769 Use : "property" ,
5870 Short : wski18n .T ("work with whisk properties" ),
@@ -287,6 +299,22 @@ var propertyGetCmd = &cobra.Command{
287299 PreRunE : SetupClientConfig ,
288300 RunE : func (cmd * cobra.Command , args []string ) error {
289301
302+ var outputFormat string = "std"
303+ if Flags .property .output != "std" {
304+ switch Flags .property .output {
305+ case "raw" :
306+ outputFormat = "raw"
307+ break
308+ //case "json": For future implementation
309+ //case "yaml": For future implementation
310+ default :
311+ errStr := fmt .Sprintf (
312+ wski18n .T ("Supported output format are std|raw" ))
313+ werr := whisk .MakeWskErrorFromWskError (errors .New (errStr ), nil , whisk .EXIT_CODE_ERR_GENERAL , whisk .DISPLAY_MSG , whisk .NO_DISPLAY_USAGE )
314+ return werr
315+ }
316+ }
317+
290318 // If no property is explicitly specified, default to all properties
291319 if ! (Flags .property .all || Flags .property .cert ||
292320 Flags .property .key || Flags .property .auth ||
@@ -295,33 +323,44 @@ var propertyGetCmd = &cobra.Command{
295323 Flags .property .apihost || Flags .property .apibuildno ) {
296324 Flags .property .all = true
297325 }
326+ if Flags .property .all {
327+ // Currently with all only standard output format is supported.
328+ if outputFormat != "std" {
329+ errStr := fmt .Sprintf (
330+ wski18n .T ("--output|-o raw only supported with specific property type" ))
331+ werr := whisk .MakeWskErrorFromWskError (errors .New (errStr ), nil , whisk .EXIT_CODE_ERR_GENERAL , whisk .DISPLAY_MSG , whisk .NO_DISPLAY_USAGE )
332+ return werr
333+ }
298334
299- if Flags .property .all || Flags .property .cert {
300- fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T ("client cert" ), boldString (Properties .Cert ))
301- }
302-
303- if Flags .property .all || Flags .property .key {
304- fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T ("Client key" ), boldString (Properties .Key ))
305- }
306-
307- if Flags .property .all || Flags .property .auth {
308- fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T ("whisk auth" ), boldString (Properties .Auth ))
309- }
310-
311- if Flags .property .all || Flags .property .apihost {
312- fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T ("whisk API host" ), boldString (Properties .APIHost ))
313- }
314-
315- if Flags .property .all || Flags .property .apiversion {
316- fmt .Fprintf (color .Output , "%s\t %s\n " , wski18n .T ("whisk API version" ), boldString (Properties .APIVersion ))
317- }
318-
319- if Flags .property .all || Flags .property .namespace {
320- fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T ("whisk namespace" ), boldString (Properties .Namespace ))
321- }
322-
323- if Flags .property .all || Flags .property .cliversion {
324- fmt .Fprintf (color .Output , "%s\t %s\n " , wski18n .T ("whisk CLI version" ), boldString (Properties .CLIVersion ))
335+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (propDisplayCert ), boldString (Properties .Cert ))
336+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (propDisplayKey ), boldString (Properties .Key ))
337+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (propDisplayAuth ), boldString (Properties .Auth ))
338+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (propDisplayAPIHost ), boldString (Properties .APIHost ))
339+ fmt .Fprintf (color .Output , "%s\t %s\n " , wski18n .T (propDisplayAPIVersion ), boldString (Properties .APIVersion ))
340+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (propDisplayNamespace ), boldString (Properties .Namespace ))
341+ fmt .Fprintf (color .Output , "%s\t %s\n " , wski18n .T (propDisplayCLIVersion ), boldString (Properties .CLIVersion ))
342+ } else {
343+ if Flags .property .cert {
344+ printProperty (Properties .Cert , propDisplayCert , outputFormat )
345+ }
346+ if Flags .property .key {
347+ printProperty (Properties .Key , propDisplayKey , outputFormat )
348+ }
349+ if Flags .property .cliversion {
350+ printProperty (Properties .CLIVersion , propDisplayCLIVersion , outputFormat , "%s\t %s\n " )
351+ }
352+ if Flags .property .apihost {
353+ printProperty (Properties .APIHost , propDisplayAPIHost , outputFormat )
354+ }
355+ if Flags .property .auth {
356+ printProperty (Properties .Auth , propDisplayAuth , outputFormat )
357+ }
358+ if Flags .property .apiversion {
359+ printProperty (Properties .APIVersion , propDisplayAPIVersion , outputFormat , "%s\t %s\n " )
360+ }
361+ if Flags .property .namespace {
362+ printProperty (Properties .Namespace , propDisplayNamespace , outputFormat )
363+ }
325364 }
326365
327366 if Flags .property .all || Flags .property .apibuild || Flags .property .apibuildno {
@@ -332,11 +371,15 @@ var propertyGetCmd = &cobra.Command{
332371 info .Build = wski18n .T ("Unknown" )
333372 info .BuildNo = wski18n .T ("Unknown" )
334373 }
335- if Flags .property .all || Flags .property .apibuild {
336- fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T ("whisk API build" ), boldString (info .Build ))
374+ if Flags .property .all {
375+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (propDisplayAPIBuild ), boldString (info .Build ))
376+ fmt .Fprintf (color .Output , "%s\t %s\n " , wski18n .T (propDisplayAPIBuildNo ), boldString (info .BuildNo ))
377+ }
378+ if Flags .property .apibuild && ! Flags .property .all {
379+ printProperty (info .Build , propDisplayAPIBuild , outputFormat )
337380 }
338- if Flags .property .all || Flags .property .apibuildno {
339- fmt . Fprintf ( color . Output , "%s\t %s\n " , wski18n . T ( "whisk API build number" ), boldString ( info . BuildNo ) )
381+ if Flags .property .apibuildno && ! Flags .property .all {
382+ printProperty ( info . BuildNo , propDisplayAPIBuildNo , outputFormat , "%s\t %s\n " )
340383 }
341384 if err != nil {
342385 errStr := fmt .Sprintf (
@@ -346,7 +389,6 @@ var propertyGetCmd = &cobra.Command{
346389 return werr
347390 }
348391 }
349-
350392 return nil
351393 },
352394}
@@ -359,30 +401,31 @@ func init() {
359401 )
360402
361403 // need to set property flags as booleans instead of strings... perhaps with boolApihost...
362- propertyGetCmd .Flags ().BoolVar (& Flags .property .cert , "cert" , false , wski18n .T ("client cert" ))
363- propertyGetCmd .Flags ().BoolVar (& Flags .property .key , "key" , false , wski18n .T ("client key" ))
404+ propertyGetCmd .Flags ().BoolVar (& Flags .property .cert , "cert" , false , wski18n .T (propDisplayCert ))
405+ propertyGetCmd .Flags ().BoolVar (& Flags .property .key , "key" , false , wski18n .T (propDisplayKey ))
364406 propertyGetCmd .Flags ().BoolVar (& Flags .property .auth , "auth" , false , wski18n .T ("authorization key" ))
365- propertyGetCmd .Flags ().BoolVar (& Flags .property .apihost , "apihost" , false , wski18n .T ("whisk API host" ))
366- propertyGetCmd .Flags ().BoolVar (& Flags .property .apiversion , "apiversion" , false , wski18n .T ("whisk API version" ))
407+ propertyGetCmd .Flags ().BoolVar (& Flags .property .apihost , "apihost" , false , wski18n .T (propDisplayAPIHost ))
408+ propertyGetCmd .Flags ().BoolVar (& Flags .property .apiversion , "apiversion" , false , wski18n .T (propDisplayAPIVersion ))
367409 propertyGetCmd .Flags ().BoolVar (& Flags .property .apibuild , "apibuild" , false , wski18n .T ("whisk API build version" ))
368- propertyGetCmd .Flags ().BoolVar (& Flags .property .apibuildno , "apibuildno" , false , wski18n .T ("whisk API build number" ))
369- propertyGetCmd .Flags ().BoolVar (& Flags .property .cliversion , "cliversion" , false , wski18n .T ("whisk CLI version" ))
370- propertyGetCmd .Flags ().BoolVar (& Flags .property .namespace , "namespace" , false , wski18n .T ("whisk namespace" ))
410+ propertyGetCmd .Flags ().BoolVar (& Flags .property .apibuildno , "apibuildno" , false , wski18n .T (propDisplayAPIBuildNo ))
411+ propertyGetCmd .Flags ().BoolVar (& Flags .property .cliversion , "cliversion" , false , wski18n .T (propDisplayCLIVersion ))
412+ propertyGetCmd .Flags ().BoolVar (& Flags .property .namespace , "namespace" , false , wski18n .T (propDisplayNamespace ))
371413 propertyGetCmd .Flags ().BoolVar (& Flags .property .all , "all" , false , wski18n .T ("all properties" ))
414+ propertyGetCmd .Flags ().StringVarP (& Flags .property .output , "output" , "o" , "std" , wski18n .T ("Output format in std|raw" ))
372415
373416 propertySetCmd .Flags ().StringVarP (& Flags .Global .Auth , "auth" , "u" , "" , wski18n .T ("authorization `KEY`" ))
374- propertySetCmd .Flags ().StringVar (& Flags .Global .Cert , "cert" , "" , wski18n .T ("client cert" ))
375- propertySetCmd .Flags ().StringVar (& Flags .Global .Key , "key" , "" , wski18n .T ("client key" ))
417+ propertySetCmd .Flags ().StringVar (& Flags .Global .Cert , "cert" , "" , wski18n .T (propDisplayCert ))
418+ propertySetCmd .Flags ().StringVar (& Flags .Global .Key , "key" , "" , wski18n .T (propDisplayKey ))
376419 propertySetCmd .Flags ().StringVar (& Flags .property .apihostSet , "apihost" , "" , wski18n .T ("whisk API `HOST`" ))
377420 propertySetCmd .Flags ().StringVar (& Flags .property .apiversionSet , "apiversion" , "" , wski18n .T ("whisk API `VERSION`" ))
378421 propertySetCmd .Flags ().StringVar (& Flags .property .namespaceSet , "namespace" , "" , wski18n .T ("whisk `NAMESPACE`" ))
379422
380- propertyUnsetCmd .Flags ().BoolVar (& Flags .property .cert , "cert" , false , wski18n .T ("client cert" ))
381- propertyUnsetCmd .Flags ().BoolVar (& Flags .property .key , "key" , false , wski18n .T ("client key" ))
423+ propertyUnsetCmd .Flags ().BoolVar (& Flags .property .cert , "cert" , false , wski18n .T (propDisplayCert ))
424+ propertyUnsetCmd .Flags ().BoolVar (& Flags .property .key , "key" , false , wski18n .T (propDisplayKey ))
382425 propertyUnsetCmd .Flags ().BoolVar (& Flags .property .auth , "auth" , false , wski18n .T ("authorization key" ))
383- propertyUnsetCmd .Flags ().BoolVar (& Flags .property .apihost , "apihost" , false , wski18n .T ("whisk API host" ))
384- propertyUnsetCmd .Flags ().BoolVar (& Flags .property .apiversion , "apiversion" , false , wski18n .T ("whisk API version" ))
385- propertyUnsetCmd .Flags ().BoolVar (& Flags .property .namespace , "namespace" , false , wski18n .T ("whisk namespace" ))
426+ propertyUnsetCmd .Flags ().BoolVar (& Flags .property .apihost , "apihost" , false , wski18n .T (propDisplayAPIHost ))
427+ propertyUnsetCmd .Flags ().BoolVar (& Flags .property .apiversion , "apiversion" , false , wski18n .T (propDisplayAPIVersion ))
428+ propertyUnsetCmd .Flags ().BoolVar (& Flags .property .namespace , "namespace" , false , wski18n .T (propDisplayNamespace ))
386429
387430}
388431
@@ -558,3 +601,21 @@ func parseConfigFlags(cmd *cobra.Command, args []string) error {
558601
559602 return nil
560603}
604+
605+ func printProperty (propertyName string , displayText string , formatType string , format ... string ) {
606+ switch formatType {
607+ case "std" :
608+ if len (format ) > 0 {
609+ fmt .Fprintf (color .Output , format [0 ], wski18n .T (displayText ), boldString (propertyName ))
610+ break
611+ }
612+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (displayText ), boldString (propertyName ))
613+ break
614+ case "raw" :
615+ fmt .Fprintf (color .Output , "%s\n " , boldString (propertyName ))
616+ break
617+ default :
618+ // In case of any other type for now print in std format.
619+ fmt .Fprintf (color .Output , "%s\t \t %s\n " , wski18n .T (displayText ), boldString (propertyName ))
620+ }
621+ }
0 commit comments