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
60
61
62
63
64
65
66
67
|
# File 'lib/gt/cli.rb', line 25
def self.run(argv)
command = argv.shift
if command.nil? || command == "--help" || command == "-h"
puts usage
return
end
if command == "--version" || command == "-v" || command == "version"
puts "gt version #{GT::VERSION}"
return
end
unless gh_installed?
raise GT::UserError, "GitHub CLI (gh) is required but not found. Install it at https://cli.github.com/"
end
state = GT::State.new
if state.active? && !RESTACK_ONLY.include?(command)
raise GT::UserError, "A restack is in progress. Run `gt restack --continue` or `gt restack --abort`."
end
case command
when "create" then GT::Commands::Create.run(argv)
when "log", "ls" then GT::Commands::Log.run(argv)
when "restack" then GT::Commands::Restack.run(argv)
when "modify", "m" then GT::Commands::Modify.run(argv)
when "sync" then GT::Commands::Sync.run(argv)
when "checkout", "co" then GT::Commands::Checkout.run(argv)
when "up" then GT::Commands::Up.run(argv)
when "down" then GT::Commands::Down.run(argv)
when "top" then GT::Commands::Top.run(argv)
else
raise GT::UserError, "Unknown command: #{command}. Run `gt --help` for usage."
end
rescue GT::UserError => e
warn "gt: #{e.message}"
exit 1
rescue GT::GitError => e
warn "gt: git error: #{e.message}"
exit 2
end
|