Class: LaunchdTools::Cmd2LaunchdCli

Inherits:
Object
  • Object
show all
Defined in:
lib/launchd_tools/cmd2launchd_cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cmd2LaunchdCli

Returns a new instance of Cmd2LaunchdCli.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/launchd_tools/cmd2launchd_cli.rb', line 7

def initialize(args)
  if args.empty?
    show_usage
    exit 0
  elsif args.length == 1
    case args.first
    when "--help"
      show_usage
      exit 0
    when "-h"
      show_usage
      exit 0
    when "--version"
      puts LaunchdTools::VERSION
      exit 0
    end
  end
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/launchd_tools/cmd2launchd_cli.rb', line 6

def args
  @args
end

Instance Method Details

#runObject



31
32
33
34
35
# File 'lib/launchd_tools/cmd2launchd_cli.rb', line 31

def run
  plist = LaunchdPlist.new
  plist.add_program_args(args)
  puts plist.to_s
end

#show_usageObject



27
28
29
# File 'lib/launchd_tools/cmd2launchd_cli.rb', line 27

def show_usage
  puts "Usage: #{$0} command [arg1] [arg2]"
end