Class: Gitem::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



5
6
7
8
# File 'lib/gitem/cli.rb', line 5

def initialize(argv)
  @argv = argv.dup
  @options = { output: nil, port: 8000, generate: true, open: false }
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitem/cli.rb', line 10

def run
  command = @argv.shift || "serve"
  case command
  when "generate", "g" then run_generate
  when "serve", "s" then run_serve
  when "help", "-h", "--help" then print_help
  when "version", "-v", "--version" then puts "gitem #{VERSION}"
  else
    warn "Unknown command: #{command}"
    print_help
    exit 1
  end
rescue Rugged::Error, Rugged::RepositoryError => e
  warn "Git error: #{e.message}"
  exit 1
rescue Error => e
  warn "Error: #{e.message}"
  exit 1
end