File: invoke.thor

package info (click to toggle)
ruby-thor 0.19.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 792 kB
  • ctags: 564
  • sloc: ruby: 7,315; makefile: 2; sh: 1
file content (131 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
class A < Thor
  include Thor::Actions

  desc "one", "invoke one"
  def one
    p 1
    invoke :two
    invoke :three
  end

  desc "two", "invoke two"
  def two
    p 2
    invoke :three
  end

  desc "three", "invoke three"
  def three
    p 3
  end

  desc "four", "invoke four"
  def four
    p 4
    invoke "defined:five"
  end

  desc "five N", "check if number is equal 5"
  def five(number)
    number == 5
  end

  desc "invoker", "invoke a b command"
  def invoker(*args)
    invoke :b, :one, ["Jose"]
  end
end

class B < Thor
  class_option :last_name, :type => :string

  desc "one FIRST_NAME", "invoke one"
  def one(first_name)
    "#{options.last_name}, #{first_name}"
  end

  desc "two", "invoke two"
  def two
    options
  end

  desc "three", "invoke three"
  def three
    self
  end

  desc "four", "invoke four"
  option :defaulted_value, :type => :string, :default => 'default'
  def four
    options.defaulted_value
  end
end

class C < Thor::Group
  include Thor::Actions

  def one
    p 1
  end

  def two
    p 2
  end

  def three
    p 3
  end
end

class Defined < Thor::Group
  class_option :unused, :type => :boolean, :desc => "This option has no use"

  def one
    p 1
    invoke "a:two"
    invoke "a:three"
    invoke "a:four"
    invoke "defined:five"
  end

  def five
    p 5
  end

  def print_status
    say_status :finished, :counting
  end
end

class E < Thor::Group
  invoke Defined
end

class F < Thor::Group
  invoke "b:one" do |instance, klass, command|
    instance.invoke klass, command, [ "Jose" ], :last_name => "Valim"
  end
end

class G < Thor::Group
  class_option :invoked, :type => :string, :default => "defined"
  invoke_from_option :invoked
end

class H < Thor::Group
  class_option :defined, :type => :boolean, :default => true
  invoke_from_option :defined
end

class I < Thor
  desc "two", "Two"
  def two
    current_command_chain
  end
end

class J < Thor
  desc "i", "I"
  subcommand :one, I
end