Class: Iterm2mintty::CLI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, io: $stdout) ⇒ CLI

Returns a new instance of CLI.



14
15
16
17
# File 'lib/iterm2mintty/cli.rb', line 14

def initialize(args, io: $stdout)
  @args = args
  @io = io
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



8
9
10
# File 'lib/iterm2mintty/cli.rb', line 8

def args
  @args
end

#ioObject (readonly)

Returns the value of attribute io.



8
9
10
# File 'lib/iterm2mintty/cli.rb', line 8

def io
  @io
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/iterm2mintty/cli.rb', line 8

def source
  @source
end

Class Method Details

.run(args) ⇒ Object



10
11
12
# File 'lib/iterm2mintty/cli.rb', line 10

def self.run(args)
  new(args).run
end

Instance Method Details

#parse_optionsObject



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/iterm2mintty/cli.rb', line 29

def parse_options
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: iterm2mintty <source filepath> [options]"
    opts.separator ""
    opts.separator "Options:"

    opts.on(
      "-o",
      "--output [FILE]",
      "FILE to output theme to (defaults to .minttyrc)"
    ) do |path|
      path ||= ".minttyrc"
      @io = File.new(path, "w")
    end

    opts.on("-v", "--version", "Prints version of Iterm2mintty") do
      puts VERSION
      exit true
    end

    opts.on("-h", "--help", "Prints this help :)") do
      puts opts

      if io.autoclose?
        io.close
      end

      exit true
    end
  end

  parser.parse!(args)

  if args.empty?
    puts parser

    if io.autoclose?
      io.close
    end

    exit false
  else
    @source = Pathname.new(args.pop)

    unless @source.exist?
      puts "Source file \"#{@source}\" does not exist."
      exit false
    end
  end
end

#runObject



19
20
21
22
23
24
25
26
27
# File 'lib/iterm2mintty/cli.rb', line 19

def run
  parse_options

  io.puts Iterm2mintty.convert(source)

  if io.autoclose?
    io.close
  end
end