Sha256: 3887d4759f85c435a730c42017d9fba2fd6f7de38acf2bd6e3340551c7275c8d
Contents?: true
Size: 1.43 KB
Versions: 3
Compression:
Stored size: 1.43 KB
Contents
module Alf module Algebra class Signature # Converts commandline arguments to operator constructor arguments def argv2args(argv) # First split over -- argv = Quickl.split_commandline_args(argv) # Parse the options and replace argv[0] by remaining arguments opts = {} argv[0] = option_parser(opts).parse!(argv[0]) opts = default_options.merge(opts) # Operands are argv[0], and can be removed oper = argv.shift # Coerce each remaining argument according to the signature args = [] with_each_arg(argv) do |name,dom,value| invalid_args!(args) if value.nil? args << Shell.from_argv(Array(value), dom) end [oper, args, opts] end # Returns a shell synopsis for this signature. # # Example: # # Alf::Algebra::Project.signature.to_shell # # => "alf project [--allbut] [OPERAND] -- ATTRIBUTES" def to_shell oper = operator.nullary? ? "" : (operator.unary? ? "[OPERAND]" : "[LEFT] RIGHT") opts = options.map{|opt| "[#{option_name(opt)}]" }.join(" ") args = arguments.map{|arg,_| "#{arg.to_s.upcase}" }.join(" -- ") optargs = "#{opts} #{oper} " + (args.empty? ? "" : "-- #{args}") "alf #{operator.rubycase_name} #{optargs.strip}".strip end end # class Signature end # module Algebra end # module Alf
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
alf-shell-0.14.0 | lib/alf/shell/ext/signature.rb |
alf-shell-0.13.1 | lib/alf/shell/ext/signature.rb |
alf-shell-0.13.0 | lib/alf/shell/ext/signature.rb |