Class: Daemonic::CLI
- Inherits:
-
Object
- Object
- Daemonic::CLI
- Defined in:
- lib/daemonic/cli.rb
Constant Summary collapse
- COMMANDS =
%w(start stop status restart help)
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize(argv, default_options = {}) ⇒ CLI
constructor
A new instance of CLI.
- #restart ⇒ Object
- #run ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(argv, default_options = {}) ⇒ CLI
8 9 10 11 |
# File 'lib/daemonic/cli.rb', line 8 def initialize(argv, = {}) @argv = argv = end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
6 7 8 |
# File 'lib/daemonic/cli.rb', line 6 def argv @argv end |
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
6 7 8 |
# File 'lib/daemonic/cli.rb', line 6 def end |
Instance Method Details
#help ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/daemonic/cli.rb', line 37 def help info "\n Usage: \#{program} COMMAND OPTIONS\n\n Available commands:\n * start Start the daemon\n * stop Stops the daemon\n * restart Stops and starts a daemonized process\n * status Shows the status\n\n To get more information about each command, run the command with --help.\n\n Example: \#{program} start --help\n\n USAGE\nend\n" |
#restart ⇒ Object
70 71 72 73 |
# File 'lib/daemonic/cli.rb', line 70 def restart = parse "restart", log: STDOUT, concurrency: 2, stop_timeout: 5, startup_timeout: 1 [ :restart, ] end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/daemonic/cli.rb', line 13 def run command = argv[0] case command when nil, "-h", "--help", "help" help exit when "-v", "--version" puts "Daemonic version #{Daemonic::VERSION}" exit when "start" start when "stop" stop when "status" status when "restart" restart else puts "Unknown command #{command.inspect}." help exit 1 end end |
#start ⇒ Object
55 56 57 58 |
# File 'lib/daemonic/cli.rb', line 55 def start = parse "start", log: STDOUT, concurrency: 2, daemonize: false, startup_timeout: 1 [ :start, ] end |
#status ⇒ Object
65 66 67 68 |
# File 'lib/daemonic/cli.rb', line 65 def status = parse "status" [ :status, ] end |
#stop ⇒ Object
60 61 62 63 |
# File 'lib/daemonic/cli.rb', line 60 def stop = parse "stop", stop_timeout: 5 [ :stop, ] end |