Class: CLI
- Inherits:
-
Thor
- Object
- Thor
- CLI
- Defined in:
- lib/crossplane/cli.rb
Instance Method Summary collapse
- #build(filename) ⇒ Object
- #lex(filename) ⇒ Object
- #minify(filename) ⇒ Object
- #parse(filename) ⇒ Object
Instance Method Details
permalink #build(filename) ⇒ Object
[View source]
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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 ['force'] and not ['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: ['indent'] || 4, # fix default option in config.rb tabs: ['tabs'], header: ['header'] ) output = output.rstrip + "\n" puts output end #puts output #end end |
permalink #lex(filename) ⇒ Object
[View source]
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/crossplane/cli.rb', line 114 def lex(filename) payload = CrossPlane::Lexer.new( filename: filename, ).lex() lex = (not ['line_numbers'].nil? and ['line_numbers'] == true) ? payload : payload.map{|e| e[0]} if ['out'] File.open(['out'], 'w') do |f| f.write(JSON.pretty_generate(lex)) end else puts ['pretty'] ? JSON.pretty_generate(lex) : lex.to_json end end |
permalink #minify(filename) ⇒ Object
[View source]
130 131 132 133 |
# File 'lib/crossplane/cli.rb', line 130 def minify(filename) puts 'minifiy' exit end |
permalink #parse(filename) ⇒ Object
[View source]
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/crossplane/cli.rb', line 38 def parse(filename) payload = CrossPlane::Parser.new( filename: filename, combine: ['combine'] || false, strict: ['strict'] || false, catch_errors: ['no_catch'] ? false : true, comments: ['include_comments'] || false, ignore: ['ignore'] ? ['ignore'].split(/\s*,\s*/) : [], single: ['single'] || false, ).parse() if ['out'] File.open(['out'], 'w') do |f| f.write(JSON.pretty_generate(payload)) end else puts ['pretty'] ? JSON.pretty_generate(payload) : payload.to_json end exit 0 end |