lib/brief/cli/parse.rb in brief-1.9.0 vs lib/brief/cli/parse.rb in brief-1.9.1

- old
+ new

@@ -1,24 +1,20 @@ command 'parse' do |c| c.syntax = 'brief parse PATH [OPTIONS]' c.description = 'parse the briefcase path' - c.option '--root PATH', String, 'The briefcase root' - c.option '--output PATH', String, 'Save the output to the specified path' - c.option '--app APP', String, 'Use the specified app to get our models etc' - c.option '--config PATH', String, 'Use the specified config file' - c.option '--type TYPE', String, 'Valid options: hash, array; Output as a hash keyed by path, or an array. Defaults to array.' + c.option '--output-type TYPE', String, 'Valid options: hash, array; Output as a hash keyed by path, or an array. Defaults to array.' + c.option '--config-path FILE', String, 'Path to the config file for the briefcase' c.action do |args, options| - options.default(root: Pathname(Brief.pwd), type: "array") + options.default(root: Pathname(Brief.pwd), output_type: "array") o = { root: options.root } - o[:app] = options.app if options.app - o[:config_path] = options.config if options.config + o[:config_path] = options.config_path if options.config_path briefcase = Brief::Briefcase.new(o) parsed = if args.empty? briefcase.all_models.map do |model| @@ -31,20 +27,16 @@ doc.to_model.as_json(content: true, rendered: true) end end.flatten end - if options.type == "hash" + if options.output_type == "hash" parsed = parsed.inject({}) do |memo, obj| path = obj[:path] memo[path] = obj memo end end - if options.output - Pathname(options.output).open("w+") {|fh| fh.write(parsed.to_json) } - else - puts parsed.to_json - end + parsed end end