This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
$LOAD_PATH.unshift File.join(__dir__, "..", "lib")
|
||||
|
||||
require "mercenary"
|
||||
|
||||
# This example sets the logging mode of mercenary to
|
||||
# debug. Logging messages from "p.logger.debug" will
|
||||
# be output to STDOUT.
|
||||
|
||||
Mercenary.program(:help_dialogue) do |p|
|
||||
p.version "2.0.1"
|
||||
p.description "An example of the help dialogue in Mercenary"
|
||||
p.syntax "help_dialogue <subcommand>"
|
||||
|
||||
p.command(:some_subcommand) do |c|
|
||||
c.version "1.4.2"
|
||||
c.syntax "some_subcommand <subcommand> [options]"
|
||||
c.description "Some subcommand to do something"
|
||||
c.option "an_option", "-o", "--option", "Some option"
|
||||
c.alias(:blah)
|
||||
|
||||
c.command(:yet_another_sub) do |f|
|
||||
f.syntax "yet_another_sub [options]"
|
||||
f.description "Do amazing things"
|
||||
f.option "blah", "-b", "--blah", "Trigger blah flag"
|
||||
f.option "heh", "-H ARG", "--heh ARG", "Give a heh"
|
||||
|
||||
f.action do |args, options|
|
||||
print "Args: "
|
||||
p args
|
||||
print "Opts: "
|
||||
p options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
p.command(:another_subcommand) do |c|
|
||||
c.syntax "another_subcommand <subcommand> [options]"
|
||||
c.description "Another subcommand to do something different."
|
||||
c.option "an_option", "-O", "--option", "Some option"
|
||||
c.option "another_options", "--pluginzzz", "Set where the plugins should be found from"
|
||||
end
|
||||
end
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
$LOAD_PATH.unshift File.join(__dir__, "..", "lib")
|
||||
|
||||
require "mercenary"
|
||||
|
||||
# This example sets the logging mode of mercenary to
|
||||
# debug. Logging messages from "p.logger.debug" will
|
||||
# be output to STDOUT.
|
||||
|
||||
Mercenary.program(:logger_output) do |p|
|
||||
p.version "5.2.6"
|
||||
p.description "An example of turning on logging for Mercenary."
|
||||
p.syntax "logger_output"
|
||||
|
||||
p.logger.info "The default log level is INFO. So this will output."
|
||||
p.logger.debug "Since DEBUG is below INFO, this will not output."
|
||||
|
||||
p.logger(Logger::DEBUG)
|
||||
p.logger.debug "Logger level now set to DEBUG. So everything will output."
|
||||
|
||||
p.logger.debug "Example of DEBUG level message."
|
||||
p.logger.info "Example of INFO level message."
|
||||
p.logger.warn "Example of WARN level message."
|
||||
p.logger.error "Example of ERROR level message."
|
||||
p.logger.fatal "Example of FATAL level message."
|
||||
p.logger.unknown "Example of UNKNOWN level message."
|
||||
|
||||
p.action do |_args, _options|
|
||||
p.logger(Logger::INFO)
|
||||
p.logger.debug "Logger level back to INFO. This line will not output."
|
||||
p.logger.info "This INFO message will output."
|
||||
end
|
||||
end
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
$LOAD_PATH.unshift File.join(__dir__, "..", "lib")
|
||||
|
||||
require "mercenary"
|
||||
|
||||
# This example sets the logging mode of mercenary to
|
||||
# debug. Logging messages from "p.logger.debug" will
|
||||
# be output to STDOUT.
|
||||
|
||||
Mercenary.program(:trace) do |p|
|
||||
p.version "2.0.1"
|
||||
p.description "An example of traces in Mercenary"
|
||||
p.syntax "trace <subcommand>"
|
||||
|
||||
p.action do |_, _|
|
||||
raise ArgumentError, "YOU DID SOMETHING TERRIBLE YOU BUFFOON"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user