diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-09-12 16:27:39 -0400 | 
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-09-12 16:27:39 -0400 | 
| commit | 6a232d1a17e69992d1f5291fff8f129ddcd7f5b1 (patch) | |
| tree | 5d29277fa37e6bebecb0270f821dec1ead485abd /lib/command.c | |
| parent | b9843e63c0ddc962ce807e33aa46255e65dfe9e9 (diff) | |
lib: Add json support for 'show version' command
Fixes: #1167
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 44 | 
1 files changed, 36 insertions, 8 deletions
diff --git a/lib/command.c b/lib/command.c index cc52224523..444305d5d5 100644 --- a/lib/command.c +++ b/lib/command.c @@ -42,6 +42,7 @@  #include "command_match.h"  #include "qobj.h"  #include "defaults.h" +#include "json.h"  DEFINE_MTYPE(LIB, HOST, "Host config")  DEFINE_MTYPE(LIB, STRVEC, "String vector") @@ -1455,15 +1456,42 @@ DEFUN (config_end,  /* Show version. */  DEFUN (show_version,         show_version_cmd, -       "show version", +       "show version [json]",         SHOW_STR -       "Displays zebra version\n") -{ -	vty_out(vty, "%s %s (%s).%s", FRR_FULL_NAME, FRR_VERSION, -		host.name ? host.name : "", VTY_NEWLINE); -	vty_out(vty, "%s%s%s", FRR_COPYRIGHT, GIT_INFO, VTY_NEWLINE); -	vty_out(vty, "configured with:%s    %s%s", VTY_NEWLINE, FRR_CONFIG_ARGS, -		VTY_NEWLINE); +       "Displays zebra version\n" +	JSON_STR) +{ +	int uj = use_json(argc, argv); +	json_object *json = NULL; + +	if (uj) { +		json = json_object_new_object(); +		json_object_string_add(json, +				       "hostName", +				       host.name ? host.name : ""); +		json_object_string_add(json, +				       "version", FRR_VERSION); +		json_object_string_add(json, +				       "name", FRR_FULL_NAME); +		json_object_string_add(json, +				       "copyright", FRR_COPYRIGHT); +		json_object_string_add(json, +				       "gitInformation", GIT_INFO); +		json_object_string_add(json, +				       "configureLine", FRR_CONFIG_ARGS); + +		vty_out(vty, "%s%s", +			json_object_to_json_string_ext(json, +						       JSON_C_TO_STRING_PRETTY), +			VTY_NEWLINE); +		json_object_free(json); +	} else { +		vty_out(vty, "%s %s (%s).%s", FRR_FULL_NAME, FRR_VERSION, +			host.name ? host.name : "", VTY_NEWLINE); +		vty_out(vty, "%s%s%s", FRR_COPYRIGHT, GIT_INFO, VTY_NEWLINE); +		vty_out(vty, "configured with:%s    %s%s", VTY_NEWLINE, FRR_CONFIG_ARGS, +			VTY_NEWLINE); +	}  	return CMD_SUCCESS;  }  | 
