Class: Conv::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ffc/cli.rb

Instance Method Summary collapse

Instance Method Details

#convert(*inputs, output) ⇒ Object

option :arguments, type: :string, aliases: ‘-a’, desc: “Set arguments to provide a certain command such as ‘-O2’”



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
# File 'lib/ffc/cli.rb', line 23

def convert(*inputs, output) # Define commands as a method.
  prompt = TTY::Prompt.new(interrupt: :exit)
  items = Conv.new.find_item(inputs, output, input_format=input_format, output_format=output_format, package_manager: options[:package_manager])
  candidate = items[0]
  if items.empty?
    prompt.error "No candidates."
    inputs << output
    list(*inputs) if !options[:hidelist]
  else
      if options[:confirm]#interactive]
        candidate = prompt.select("Choose commands (To cancel, press CTRL+C)", items) #do |item|
      end
      prompt.ok candidate.cmd(inputs, output) unless options[:quiet]
      return if !options[:overwrite] && !ask_overwrite(output) || options[:dryrun]
      status, stdout, stderr = candidate.run!(inputs, output, options[:arguments])
      prompt.ok stdout
      prompt.error stderr
      if status != 0
        if options[:autobrew] || !prompt.no?("Install " + candidate.package + " with package manager? (" + candidate.brew_command + ")")
          status, stdout, stderr = candidate.brew!
          prompt.say stdout
          prompt.error stderr
          if status == 0
            status, stdout, stderr = candidate.run!(inputs, output)
            prompt.ok stdout
            prompt.error stderr
          end
        end
      else
        Conv.update!(candidate) unless options[:onetime]
      end
  end
end

#index(input) ⇒ Object



113
114
115
# File 'lib/ffc/cli.rb', line 113

def index(input)
#
end

#list(*inputs) ⇒ Object



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
# File 'lib/ffc/cli.rb', line 67

def list(*inputs)
  prompt = TTY::Prompt.new(interrupt: :exit)
  items = Conv.new.list(inputs, input_format=input_format, package_manager: options[:package_manager])
  #p inputs,items
  if items.empty?
    prompt.error "No candidates."
    return
  end
  if !options[:showonly]
    candidate = prompt.select("Choose commands (To cancel: CTRL+C)", items) #do |item|
    option = options[:add_prefix] ? :prefix : :exchange
    output = candidate.generate_output_filename(inputs[0], option)

    return if !options[:overwrite] && !ask_overwrite(output) || options[:dryrun]
    prompt.ok candidate.cmd(inputs, output) unless options[:quiet]
    status, stdout, stderr = candidate.run!(inputs, output)#(options[:autobrew])
    prompt.say stdout
    prompt.error stderr
    if status != 0
      if options[:autobrew] || !prompt.no?("Install " + candidate.package + " with package manager? (" + candidate.brew_command + ")")
          status, stdout, stderr = candidate.brew!
          prompt.say stdout
          prompt.error stderr
          if status == 0
            status, stdout, stderr = candidate.run!(inputs, output)
            prompt.say stdout
            prompt.error stderr
          end
      end
    else
      Conv.update!(candidate) unless options[:onetime]
    end
  else
    prompt.say items.join("")

  end
end

#rehashObject



118
119
120
# File 'lib/ffc/cli.rb', line 118

def rehash
  Conv.save!
end

#sort(input) ⇒ Object



107
108
109
# File 'lib/ffc/cli.rb', line 107

def sort(input)
#
end