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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
|
class MyScript < Thor
check_unknown_options! :except => :with_optional
def self.exit_on_failure?
false
end
attr_accessor :some_attribute
attr_writer :another_attribute
attr_reader :another_attribute
private
attr_reader :private_attribute
public
group :script
default_command :example_default_command
map "-T" => :animal, ["-f", "--foo"] => :foo
map "animal_prison" => "zoo"
desc "zoo", "zoo around"
def zoo
true
end
desc "animal TYPE", "horse around"
no_commands do
no_commands do
def this_is_not_a_command
end
end
def neither_is_this
end
end
def animal(type)
[type]
end
map "hid" => "hidden"
desc "hidden TYPE", "this is hidden", :hide => true
def hidden(type)
[type]
end
map "fu" => "zoo"
desc "foo BAR", <<END
do some fooing
This is more info!
Everyone likes more info!
END
method_option :force, :type => :boolean, :desc => "Force to do some fooing"
def foo(bar)
[bar, options]
end
method_option :all, :desc => "Do bazing for all the things"
desc ["baz THING", "baz --all"], "super cool"
def baz(thing = nil)
raise if thing.nil? && !options.include?(:all)
end
desc "example_default_command", "example!"
method_options :with => :string
def example_default_command
options.empty? ? "default command" : options
end
desc "call_myself_with_wrong_arity", "get the right error"
def call_myself_with_wrong_arity
call_myself_with_wrong_arity(4)
end
desc "call_unexistent_method", "Call unexistent method inside a command"
def call_unexistent_method
boom!
end
desc "long_description", "a" * 80
long_desc <<-D
This is a really really really long description.
Here you go. So very long.
It even has two paragraphs.
D
def long_description
end
desc "name-with-dashes", "Ensure normalization of command names"
def name_with_dashes
end
desc "long_description", "a" * 80
long_desc <<-D, wrap: false
No added indentation, Inline
whatespace not merged,
Linebreaks preserved
and
indentation
too
D
def long_description_unwrapped
end
method_options :all => :boolean
method_option :lazy, :lazy_default => "yes"
method_option :lazy_numeric, :type => :numeric, :lazy_default => 42
method_option :lazy_array, :type => :array, :lazy_default => %w[eat at joes]
method_option :lazy_hash, :type => :hash, :lazy_default => {'swedish' => 'meatballs'}
desc "with_optional NAME", "invoke with optional name"
def with_optional(name=nil, *args)
[name, options, args]
end
class AnotherScript < Thor
desc "baz", "do some bazing"
def baz
end
end
desc "send", "send as a command name"
def send
true
end
private
def method_missing(meth, *args)
if meth == :boom!
super
else
[meth, args]
end
end
desc "what", "what"
def what
end
end
class MyChildScript < MyScript
remove_command :name_with_dashes
method_options :force => :boolean, :param => :numeric
def initialize(*args)
super
end
desc "zoo", "zoo around"
method_options :param => :required
def zoo
options
end
desc "animal TYPE", "horse around"
def animal(type)
[type, options]
end
method_option :other, :type => :string, :default => "method default", :for => :animal
desc "animal KIND", "fish around", :for => :animal
desc "boom", "explodes everything"
def boom
end
remove_command :boom, :undefine => true
end
class Barn < Thor
def self.exit_on_failure?
false
end
desc "open [ITEM]", "open the barn door"
def open(item = nil)
if item == "shotgun"
puts "That's going to leave a mark."
else
puts "Open sesame!"
end
end
desc "paint [COLOR]", "paint the barn"
method_option :coats, :type => :numeric, :default => 2, :desc => 'how many coats of paint'
def paint(color='red')
puts "#{options[:coats]} coats of #{color} paint"
end
end
class PackageNameScript < Thor
package_name "Baboon"
end
module Scripts
class MyScript < MyChildScript
argument :accessor, :type => :string
class_options :force => :boolean
method_option :new_option, :type => :string, :for => :example_default_command
def zoo
self.accessor
end
end
class MyDefaults < Thor
check_unknown_options!
def self.exit_on_failure?
false
end
namespace :default
desc "cow", "prints 'moo'"
def cow
puts "moo"
end
desc "command_conflict", "only gets called when prepended with a colon"
def command_conflict
puts "command"
end
desc "barn", "commands to manage the barn"
subcommand "barn", Barn
end
class ChildDefault < Thor
namespace "default:child"
end
class Arities < Thor
def self.exit_on_failure?
false
end
desc "zero_args", "takes zero args"
def zero_args
end
desc "one_arg ARG", "takes one arg"
def one_arg(arg)
end
desc "two_args ARG1 ARG2", "takes two args"
def two_args(arg1, arg2)
end
desc "optional_arg [ARG]", "takes an optional arg"
def optional_arg(arg='default')
end
desc ["multiple_usages ARG --foo", "multiple_usages ARG --bar"], "takes mutually exclusive combinations of args and flags"
def multiple_usages(arg)
end
end
end
class Apple < Thor
namespace :fruits
desc 'apple', 'apple'; def apple; end
desc 'rotten-apple', 'rotten apple'; def rotten_apple; end
map "ra" => :rotten_apple
end
class Pear < Thor
namespace :fruits
desc 'pear', 'pear'; def pear; end
end
class MyClassOptionScript < Thor
class_option :free
class_exclusive do
class_option :one
class_option :two
end
class_at_least_one do
class_option :three
class_option :four
end
desc "mix", ""
exclusive do
at_least_one do
option :five
option :six
option :seven
end
end
def mix
end
end
class MyOptionScript < Thor
desc "exclusive", ""
exclusive do
method_option :one
method_option :two
method_option :three
end
method_option :after1
method_option :after2
def exclusive
end
exclusive :after1, :after2, {:for => :exclusive}
desc "at_least_one", ""
at_least_one do
method_option :one
method_option :two
method_option :three
end
method_option :after1
method_option :after2
def at_least_one
end
at_least_one :after1, :after2, :for => :at_least_one
desc "only_one", ""
exclusive do
at_least_one do
option :one
option :two
option :three
end
end
def only_one
end
desc "no_relastions", ""
option :no_rel1
option :no_rel2
def no_relations
end
end
|