Module: UacSh

Defined in:
lib/uac_sh.rb

Overview

EXE_PACKAGE_DIRECTIVE

Class Method Summary collapse

Class Method Details

.parse_meta_args(options, args) ⇒ Object



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
# File 'lib/uac_sh.rb', line 15

def self.parse_meta_args options, args
  option_parser = OptionParser.new do |opt|
    opt.banner = <<-EOF
Usage: uac <OPTIONS> <COMMAND>

For examples please see https://github.com/winteryoung/uac
EOF

    opt.separator ""
    opt.separator "Options:"

    terminal_help = 'The given command will be executed in a terminal window, so cmd /c is added implictly. This is enabled by default.'
    opt.on('-t', '--[no-]terminal', terminal_help) do |o|
      options[:terminal] = o
      if not o
        options[:pause] = o
        options[:cd] = o
      end
    end

    pause_help = 'Pause after execution. This implies executing command line, so cmd.exe is the program to be executed. This option implies --terminal. This is enabled by default.'
    opt.on('-p', '--[no-]pause', pause_help) do |o|
      options[:pause] = o
      if o
        options[:terminal] = o
      end
    end

    opt.on('--debug') do |o|
      options[:debug] = o
    end

    opt.on('--cd', '-c', 'Change to current directory. Default is true. This option implies --terminal.') do |o|
      options[:cd] = o
      if o
        options[:terminal] = o
      end
    end

    opt.on_tail('-h', '--help', 'Print this help.') do |o|
      puts opt
      exit
    end
  end.parse! args
end

.run(options, args) ⇒ Object



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
# File 'lib/uac_sh.rb', line 61

def self.run options, args
  (meta_args, args) = split_args args

  all_options = args.all? do |arg|
    arg.start_with? "-"
  end
  if all_options
    meta_args = args
    args = []
  end

  options = {
    :pause => true,
    :terminal => true,
    :cd => true
  }.merge options

  parse_meta_args options, meta_args

  if options[:debug]
    puts "options: #{options}"
    puts "args: #{args}"
  end

  if not args or args.empty?
    exit
  end

  Uac.shell_execute options, args
end

.split_args(args) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/uac_sh.rb', line 6

def self.split_args args
  i = args.index '--'
  if i
    return [ args[0...i], args[(i+1)..-1] ]
  else
    return [ [], args ]
  end
end