diff options
author | Leah Neukirchen <leah@vuxu.org> | 2018-08-05 17:44:32 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-08-05 17:44:32 +0200 |
commit | 61efcde6f2eb0d0f32abb3f2befe07907f023b5c (patch) | |
tree | 45865c9a8c2770d1b4467d4cd8a96fce8c90701b | |
parent | 2ffed364f8a9db879eb270abb39427ed9ed9a725 (diff) | |
download | sson-61efcde6f2eb0d0f32abb3f2befe07907f023b5c.tar.gz sson-61efcde6f2eb0d0f32abb3f2befe07907f023b5c.tar.xz sson-61efcde6f2eb0d0f32abb3f2befe07907f023b5c.zip |
add simple sson command line tool
-rwxr-xr-x | bin/sson | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bin/sson b/bin/sson new file mode 100755 index 0000000..e24cd48 --- /dev/null +++ b/bin/sson @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby + +$: << "../lib" +require 'sson' + +raw = false +if ARGV.first == "-r" + ARGV.shift + raw = true +end + +input = ARGF.read + +begin + case input[0] + when "{", "[", '"' + if raw + puts SSON.generate(JSON.parse(input)) + else + puts SSON.pretty_generate(JSON.parse(input)) + end + else + if raw + puts JSON.generate(SSON.parse(input)) + else + puts JSON.pretty_generate(SSON.parse(input)) + end + end +rescue SSON::SSONError, JSON::JSONError => e + abort "error: " + e.message +end |