Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reworked sm-json to use binary created with Google go

  • Loading branch information...
commit d4118ce11a2870e339d3e7091b74d925d944e6c8 1 parent f4915d3
Long Nguyen longnguyen11288 authored
67 bin/sm-json
View
@@ -1,67 +0,0 @@
-#!/usr/bin/perl -w
-
-BEGIN{ push @INC, $ENV{'sm_path'}."/core/internal/perl"; }
-
-use JSON -support_by_pp; # http://search.cpan.org/~makamaka/JSON-2.53/lib/JSON.pm
-
-sub fail { print STDERR join(" ", @_)."\n"; exit 1; }
-
-my (
- $path, $json_file, $json_file_handle, $json_object, $json, $key, $namespace,
- $hash, $subhash, $reference
-);
-
-$path = shift(@ARGV);
-$json_file = shift(@ARGV);
-
-if( ! $path ) {
- fail "ERROR: A json path to extract must be given as the first argument\nexample: 'system/hostname'."
-} elsif ( ! $json_file ) {
- fail "ERROR: A json file must be given as the second argument."
-} elsif( ! -e $json_file ) {
- fail "ERROR: The json file $json_file does not exist!"
-}
-
-open($json_file_handle, '<', $json_file);
-$json_string = join("", <$json_file_handle>);
-close($json_file_handle);
-
-$json_object = new JSON;
-$json = $json_object->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($json_string);
-
-@_ = split("/", $path);
-$key = pop(@_);
-$namespace = join("/", @_);
-$hash = $json;
-$subhash = {};
-
-if($namespace) {
- foreach(split("/", $namespace)) {
- if(! $hash->{$_}) {
- exit 0 # No value.
- } elsif(exists $hash->{$_}) {
- # TODO: Question: Proper way to reassign the hash to it's subhash, this
- # works however I am not sure if there is an easier one liner that does
- # not involve a 2nd variable (subhash).
- $subhash = $hash->{$_};
- $hash = $subhash; # reassign the hash to the value of the current key (namespace).
- } else {
- fail "ERROR: Namespace ${namespace} missing under path '".join("/", $path)."'";
- }
- }
-}
-
-$reference = \$hash->{$key};
-
-if (ref($reference) eq "SCALAR") {
- printf "%s\n", $hash->{$key};
-} elsif (ref($$reference) eq "ARRAY") {
- print STDOUT join(" ", @{$hash->{$key}}) . "\n"; # TODO: Think this out a bit more.
-} elsif (ref($hash->{$key}) eq "HASH") {
- # This allows for namespace querying to reflect on available keys.
- printf "%s\n", join(" ",keys(%{$hash->{$key}}));
-} else {
- fail "ERROR: Key '$key' missing under namespace '$namespace' missing for path '$path'.";
-}
-
-exit 0; # Success!!!
1  core/install/shell/functions
View
@@ -238,7 +238,6 @@ install_sm_mustache()
install_sm_json()
{
- return 0 # Remove this line once sm-json is ready.
typeset _url
if [[ -s "${install_path}/bin/sm-json" ]]
then
16 core/internal/shell/json/functions
View
@@ -30,7 +30,7 @@ __sm.json.cli()
__sm.json.get()
{
trace_filter json || set -o xtrace
- typeset _type _path _default _variable _json_uri _json_uri_src _array_name
+ typeset _type _path _default _variable _json_uri _json_uri_src _array_name _value
_json_uri_src="$1" && shift
_json_uri="${sm_temp_path}/${_json_uri_src##*/}"
@@ -79,9 +79,10 @@ __sm.json.get()
fi
typeset -g ${_variable} >/dev/null
-
- if ! eval "${_variable}=$("${sm_path}/bin/sm-json" "${_path}" "${_json_uri}")"
- then eval "${_variable}=\"\""
+
+ if _value="$( "${sm_path}/bin/sm-json" -path "${_path}" -uri "${_json_uri}" )"
+ then eval "${_variable}=\"${_value}\""
+ else eval "${_variable}=\"${_default}\""
fi
if eval "[[ -z \"\${${_variable}}\" ]]"
@@ -115,9 +116,10 @@ __sm.json.get()
typeset -gxa ${_variable} >/dev/null
- if ! eval "${_variable}=($("${sm_path}/bin/sm-json" "${_path}" "${_json_uri}"))"
- then eval "${_variable}=()"
- fi
+ if _value="$( "${sm_path}/bin/sm-json" -path "${_path}" -uri "${_json_uri}" )"
+ then eval "${_variable}=\"${_value}\""
+ else eval "${_variable}=\"${_default}\""
+ fi
if eval "[[ -z \"\${${_variable}}\" ]]"
then eval "${_variable}=(\"${_default}\")"
Please sign in to comment.
Something went wrong with that request. Please try again.