Class: Bucket::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bucket/cli.rb

Constant Summary collapse

CONFIG_FILE_PATH =
"#{Dir.home}/.bucket"

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



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

def initialize(*args)
  super

  @client = Bucket::Client.new(load_config)
end

Instance Method Details

#clone(name) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/bucket/cli.rb', line 34

def clone(name)
  begin
    repository = Git::Base.clone(@client.repo_url(name), name)
    say("Repository cloned to #{repository.dir}")
  rescue Git::GitExecuteError => e
    say("Could not clone repository")
    say(e.message)
  end
end

#init(directory) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bucket/cli.rb', line 48

def init(directory)
  expanded_dir = File.expand_path(directory)
  repository = Git::Base.init(expanded_dir)

  # Create the BitBucket repository and add it to the local remotes
  remote_repository = @client.create_repo(options[:name] || File.basename(expanded_dir), options)
  remote_url = @client.repo_url("#{remote_repository[:owner]}/#{remote_repository[:slug]}")
  repository.add_remote("BitBucket", remote_url)

  say("Repository #{@client.repo_full_name(remote_repository)} with remote #{remote_url} created.")
end

#reposObject



27
28
29
30
31
# File 'lib/bucket/cli.rb', line 27

def repos
  @client.repos_list.each do |repo|
    say(@client.repo_full_name(repo))
  end
end

#setupObject



20
21
22
23
24
# File 'lib/bucket/cli.rb', line 20

def setup
  generate_config

  say("Configuration saved to ~/.bucket")
end