Class: DataForge::CLI::Options
- Inherits:
-
Object
- Object
- DataForge::CLI::Options
- Defined in:
- lib/data_forge/cli/options.rb
Instance Attribute Summary collapse
-
#command_script ⇒ Object
Returns the value of attribute command_script.
-
#execute ⇒ Object
Returns the value of attribute execute.
-
#user_params ⇒ Object
Returns the value of attribute user_params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
55 56 57 58 |
# File 'lib/data_forge/cli/options.rb', line 55 def initialize @execute = true @user_params = {} end |
Instance Attribute Details
#command_script ⇒ Object
Returns the value of attribute command_script.
51 52 53 |
# File 'lib/data_forge/cli/options.rb', line 51 def command_script @command_script end |
#execute ⇒ Object
Returns the value of attribute execute.
51 52 53 |
# File 'lib/data_forge/cli/options.rb', line 51 def execute @execute end |
#user_params ⇒ Object
Returns the value of attribute user_params.
51 52 53 |
# File 'lib/data_forge/cli/options.rb', line 51 def user_params @user_params end |
Class Method Details
.parse(args, output = STDOUT) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/data_forge/cli/options.rb', line 7 def self.parse(args, output = STDOUT) args = args.dup = new OptionParser.new do |parser| parser.default_argv = args parser. = "Usage: [bundle exec] forge [options] command_script.rb" parser.separator "" parser.separator "Options:" parser.on("-Uname=value", /^(?<name>\w+)=(?<value>\S+)$/, "User-defined parameter value to be passed to the command script.", "Can be specified multiple times (with a different name).") do |_, name, value| .user_params[name.to_sym] = value end parser.separator "" parser.separator "Common options:" parser.on_tail("-h", "--help", "Show this message") do output.puts parser .execute = false end parser.on_tail("-v", "--version", "Show version information") do output.puts "DataForge, version #{DataForge::VERSION}" .execute = false end end.parse! if .execute raise "No command script specified" if args.empty? raise "More than one command script specified" unless args.size == 1 .command_script = args.first end end |