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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/git_wand/cli.rb', line 16
def self.perform(options: [])
arguments = {
private: false,
}
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: git-wand [options]"
opts.on("--current-user-info", "Shows current user info") do
arguments[:command] = :current_user_info
end
opts.on("--create-repository REPOSITORY_NAME", "creates a repository with the given name, for the current user") do |repository_name|
arguments[:command] = :create_repository
arguments[:repository_name] = repository_name
end
opts.on("--private", "when creating a repository, sets it as private") do
arguments[:private] = true
end
opts.on("--delete-repository REPOSITORY_NAME", "delete a repository with the given name, owned by the current user") do |repository_name|
arguments[:command] = :delete_repository
arguments[:repository_name] = repository_name
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end
opt_parser.parse!(options)
if Utils.blank?(arguments[:command])
puts opt_parser
exit 1
end
result = load_config_file
case result[:status]
when :config_not_found
setup_config_file(config_path: result[:candidate_path])
exit 0
when :error
exit 1
when :ok
username = result[:data]["github_username"]
token = result[:data]["github_token"]
end
client = GitWand::GitHub::API::Client.new(
username: username,
token: token
)
Command.perform(arguments: arguments, client: client)
end
|