Sha256: 26b6f875043f0f3fed1153d33eeb9571edb919ca0f88586a98cf0880fd63dcb7
Contents?: true
Size: 1.37 KB
Versions: 29
Compression:
Stored size: 1.37 KB
Contents
#!/usr/bin/env ruby $: << File.expand_path('lib') require 'cl' class Bool < Cl::Cmd arg :bool, type: :bool def run [registry_key, bool: bool] end end class Types < Cl::Cmd arg :a, type: :bool arg :b, type: :int arg :c, type: :float arg :d def run [registry_key, a: a, b: b, c: c, d: d] end end def output(cmd, args) args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ') puts "Called #{cmd} with #{args}\n\n" end output *Cl.new($0).run(%w(bool on)) # Output: # # Called bool with bool=true output *Cl.new($0).run(%w(bool on)) # Output: # # Called bool with bool=true output *Cl.new($0).run(%w(bool on)) # Output: # # Called bool with bool=true output *Cl.new($0).run(%w(bool on)) # Output: # # Called bool with bool=true output *Cl.new($0).run(%w(types true 1 1.2 foo)) # Output: # # Called types with a=true b=1 c=1.2 d="foo" Cl.new($0).run(%w(types true 1 1.2)) # Output: # # Too many arguments (given: 5, allowed: 4) # # Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d] Cl.new($0).run(%w(types true one 1.2)) # Output: # # Wrong argument type (given: "one", expected: int) # # Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d] Cl.new($0).run(%w(types true 1 one)) # Output: # # Wrong argument type (given: "one", expected: float) # # Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]
Version data entries
29 entries across 29 versions & 1 rubygems