class CLI
Public Instance Methods
build(filename)
click to toggle source
# File lib/crossplane/cli.rb, line 61 def build(filename) dirname = Dir.pwd unless dirname # read the json payload from the specified file payload = JSON.parse(File.read(filename)) builder = CrossPlane::Builder.new( payload: payload['config'][0]['parsed'] ) if not options['force'] and not options['stdout'] existing = [] payload['config'].each do |config| path = config['file'] p = Pathname.new(path) path = p.absolute? ? path: File.join(dirname, path) if File.exist?(path) existing.push(path) end end # ask the user if it's okay to overwrite existing files if existing.length > 0 puts(format('building %s would overwrite these files:', filename)) puts existing.join("\n") # if not _prompt_yes(): # print('not overwritten') # return end end # if stdout is set then just print each file after another like nginx -T #if options['stdout'] payload['config'].each do |config| path = config['file'] p = Pathname.new(path) path = p.absolute? ? path: File.join(dirname, path) parsed = config['parsed'] output = builder.build( parsed, indent: options['indent'] || 4, # fix default option in config.rb tabs: options['tabs'], header: options['header'] ) output = output.rstrip + "\n" puts output end #puts output #end end
lex(filename)
click to toggle source
# File lib/crossplane/cli.rb, line 114 def lex(filename) payload = CrossPlane::Lexer.new( filename: filename, ).lex() lex = (not options['line_numbers'].nil? and options['line_numbers'] == true) ? payload : payload.map{|e| e[0]} if options['out'] File.open(options['out'], 'w') do |f| f.write(JSON.pretty_generate(lex)) end else puts options['pretty'] ? JSON.pretty_generate(lex) : lex.to_json end end
minify(filename)
click to toggle source
# File lib/crossplane/cli.rb, line 130 def minify(filename) puts 'minifiy' exit end
parse(filename)
click to toggle source
# File lib/crossplane/cli.rb, line 38 def parse(filename) payload = CrossPlane::Parser.new( filename: filename, combine: options['combine'] || false, strict: options['strict'] || false, catch_errors: options['no_catch'] ? false : true, comments: options['include_comments'] || false, ignore: options['ignore'] ? options['ignore'].split(/\s*,\s*/) : [], single: options['single'] || false, ).parse() if options['out'] File.open(options['out'], 'w') do |f| f.write(JSON.pretty_generate(payload)) end else puts options['pretty'] ? JSON.pretty_generate(payload) : payload.to_json end exit 0 end