Class: Pullall
Constant Summary collapse
- SUB_COMMANDS =
%w(add rm ls)
Constants included from Actions
Class Method Summary collapse
Methods included from Actions
colorize, get_real_paths, list_groups, load_all, load_paths, pluralize, pull, remove_group, remove_paths, save_all, save_paths
Class Method Details
.run(*args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pullall.rb', line 43 def self.run(*args) cmd = args.shift # Set options for each subcommand cmd_opts = case cmd when "add" Trollop:: do opt :group, "Group that will contain all the given paths", short: "-g", type: :string end when "rm" Trollop:: do opt :group, "Group from which all the given paths will be deleted", short: "-g", type: :string end end case cmd when "add" group = cmd_opts[:group] if group group_opt_index = args.index('-g') || args.index('--group') paths = get_real_paths(args - args[group_opt_index..group_opt_index + 1]) save_paths(*paths, cmd_opts[:group]) else Trollop::die "You must define a group name using -g option" end when "ls" list_groups when "rm" group = cmd_opts[:group] if group group_opt_index = args.index('-g') || args.index('--group') paths = get_real_paths(args - args[group_opt_index..group_opt_index + 1]) if paths.empty? remove_group(group) else remove_paths(*paths, group) end else Trollop::die "You must define a group name using -g option" end else # pullall <group> if args.size == 0 and cmd pull(cmd) else Trollop::die "Unknown subcommand" end end end |