Sha256: f83732a18e41636b16f2dbe1968e66b0a5cb10a0d8f2412baefb1a974d070ccc
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
require 'nymphia' require 'optparse' require 'pathname' class Nymphia::CLI def self.start(argv) new(argv).run end def initialize(argv) @argv = argv.dup parser.parse!(@argv) end def run validate_args! dsl_code_file = File.open(@file_path) absolute_dsl_file_path = File.absolute_path(dsl_code_file.path) dsl_code = dsl_code_file.read dsl = Nymphia::DSL.new(dsl_code, absolute_dsl_file_path) dsl.compile if @output_file_path dsl.render(File.open(@output_file_path, 'w')) else dsl.render(STDOUT) end end private def parser @parser ||= OptionParser.new do |opts| opts.banner = 'nymphia' opts.version = Nymphia::VERSION opts.on('-f', '--file=FILE', 'Your DSL code file') { |f| @file_path = f } opts.on('-o', '--output=FILE', 'Output file (default: stdout)') { |o| @output_file_path = o } end end def validate_args! unless @file_path raise ArgumentError.new('-f (--file) options is required.') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nymphia-0.1.1 | lib/nymphia/cli.rb |
nymphia-0.1.0 | lib/nymphia/cli.rb |