Class: WIP::CLI::Shell

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/wip/cli.rb

Constant Summary

Constants inherited from Thor

Thor::HELP_MAPPINGS, Thor::THOR_RESERVED_WORDS, Thor::VERSION

Instance Attribute Summary

Attributes included from Thor::Actions

#behavior

Attributes included from Thor::Base

#options

Instance Method Summary collapse

Methods included from Thor::Actions

#action, #append_file, #apply, #chmod, #copy_file, #create_file, #destination_root, #destination_root=, #directory, #empty_directory, #find_in_source_paths, #get, #gsub_file, #in_root, included, #inject_into_class, #inject_into_file, #inside, #prepend_file, #relative_to_original_destination_root, #remove_file, #run, #run_ruby_script, #source_paths, #template, #thor

Methods inherited from Thor

check_unknown_options!, check_unknown_options?, default_task, desc, #help, help, long_desc, map, method_option, method_options, printable_tasks, subcommand, subcommands, task_help

Methods included from Thor::Base

included, register_klass_file, shell, shell=, subclass_files, subclasses

Constructor Details

#initialize(*args) ⇒ Shell

Returns a new instance of Shell.



24
25
26
27
28
29
30
# File 'lib/wip/cli.rb', line 24

def initialize(*args)
  super
  use_shell = options["no-color"] ? Thor::Shell::Basic.new : shell

  WIP.ui = UI::Shell.new(use_shell)
  Gem::DefaultUserInteraction.ui = UI::RGProxy.new(WIP.ui)
end

Instance Method Details

#backObject



72
73
74
# File 'lib/wip/cli.rb', line 72

def back(*)
  WIP.ui.info ENV['WIP_BACK']
end

#index(path = nil) ⇒ Object



55
56
57
58
59
60
# File 'lib/wip/cli.rb', line 55

def index(path = nil, *)
  @_index ||= WIP::CLI::Index.new(path || '.')
  @_index.get(:sort => :name).each do |work|
    WIP.ui.info "  * #{work[:name]}\n    #{work[:path]}"
  end
end

#route(*args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wip/cli.rb', line 35

def route(*args)
  @_all_tasks    ||= self.class.all_tasks
  @_public_names ||= @_all_tasks.inject([]) do |memo, hash|
    memo << hash[0] unless hash[1].hidden?
    memo
  end

  # TODO: be sure we cannot loop (send :route)
  if @_public_names.include?(args.first)
    send(args.shift, *args)
  else
    # no matching task: see if there's a "work" to show
    show(*args)
  end
end

#show(path = nil) ⇒ Object



66
67
68
69
# File 'lib/wip/cli.rb', line 66

def show(path = nil, *)
  @_show ||= WIP::CLI::Show.new(path || '.')
  WIP.ui.info @_show.get
end