Module: GitWand::CLI

Defined in:
lib/git_wand/cli.rb,
lib/git_wand/cli/utils.rb,
lib/git_wand/cli/command.rb,
lib/git_wand/cli/version.rb,
lib/git_wand/cli/command/create_repository.rb,
lib/git_wand/cli/command/current_user_info.rb,
lib/git_wand/cli/command/delete_repository.rb

Defined Under Namespace

Modules: Command, Utils

Constant Summary collapse

SEARCH_CONFIG_PATHS =
[
  "./.git_wand.json",
  "~/.git_wand.json",
]
VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.perform(options: []) ⇒ Object



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