Skip to content

Instantly share code, notes, and snippets.

@paneq
Created February 5, 2013 11:01
Show Gist options
  • Save paneq/4713739 to your computer and use it in GitHub Desktop.
Save paneq/4713739 to your computer and use it in GitHub Desktop.
gli 2 hack for supporting multiple usage of same switch
#!/usr/bin/env ruby
require 'gli'
include GLI::App
AsdMulti = Object.new
asd = []
accept(AsdMulti) do |value|
asd << value
asd
end
program_desc 'A simple todo list'
desc 'Be verbose'
switch [:v,:verbose]
desc 'List tasks'
long_desc 'Lists all tasks that have yet to be completed by the user.'
$todo_list = [1,2,3]
command :list do |c|
c.desc 'Show completed tasks as well as incomplete tasks'
c.switch [:a,:all]
c.flag "asd", type: AsdMulti
c.action do |global_options,options,args|
puts args.inspect
puts options.inspect
show = options[:all] ? :all : :incomplete
$todo_list.each do |todo|
printf("%s\n", todo)
end
end
end
exit run(ARGV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment