Class: Reflex::Packager::CLI
- Inherits:
-
Object
- Object
- Reflex::Packager::CLI
- Defined in:
- lib/reflex/packager/cli.rb
Overview
Command line interface for a packager executable. Instantiated with the runtime profile to package for (Reflex by default).
Instance Method Summary collapse
- #create(argv) ⇒ Object
-
#initialize(profile) ⇒ CLI
constructor
A new instance of CLI.
- #package(argv) ⇒ Object
- #run(argv) ⇒ Object
Constructor Details
#initialize(profile) ⇒ CLI
Returns a new instance of CLI.
17 18 19 |
# File 'lib/reflex/packager/cli.rb', line 17 def initialize(profile) @profile = profile end |
Instance Method Details
#create(argv) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reflex/packager/cli.rb', line 42 def create(argv) argv, = parse argv, "Usage: #{@profile.command} new NAME" name = argv.shift raise Error, 'project name required' unless name raise Error, "'#{name}' already exists" if File.exist? name FileUtils.mkdir_p name @profile.templates.each do |path, content| File.write File.join(name, path.to_s), gsub_template(content, name) end puts "Created #{name}/" hints = [ ["cd #{name} && ruby #{@profile.templates.keys.first}", "run the application"], ["cd #{name} && #{@profile.command} package .", "package as an application"] ] max = hints.map {|cmd,| cmd.length}.max hints.each {|cmd, desc| puts " #{cmd.ljust max} # #{desc}"} end |
#package(argv) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/reflex/packager/cli.rb', line 63 def package(argv) profile = @profile argv, params = parse argv, "Usage: #{profile.command} package [options] [DIR]" do on '--platform PLATFORM', 'target platform (default: macos)' on '--config PATH', "config file path (default: DIR/#{profile.config_files.first})" on '--generate-only', 'generate project files but do not build' on '--verbose', 'verbose output' end dir = argv.shift || '.' platform = (params[:platform] || 'macos').to_sym klass = PLATFORMS[platform] || raise(Error, "unknown platform: '#{platform}'") config = Config.load profile, dir, params[:config] klass.new(config, verbose: params[:verbose]) .package generate_only: params[:'generate-only'] end |
#run(argv) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/reflex/packager/cli.rb', line 21 def run(argv) argv = argv.dup parser = OptionParser.new do |o| o.on('--version') {puts @profile.version; return} o.on('-h', '--help') {puts usage; return} end parser.order! argv case command = argv.shift when 'new' then create argv when 'package' then package argv when nil then puts usage else $stderr.puts "unknown command: '#{command}'", '', usage exit 1 end rescue OptionParser::ParseError, Error => e $stderr.puts "Error: #{e.}" exit 1 end |