Module: Gill::CLI

Includes:
Helper
Included in:
Gill
Defined in:
lib/gill/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#ask, #basename, #blue, #folder_empty?, #green, #parent, #red

Class Method Details

.importObject

Import any preexisting repos intop the gill cache.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gill/cli.rb', line 42

def CLI.import
  begin
    search = Import.new
    search.import
    search.update_cache
    exit -1
  rescue => e
    STDERR.puts "Error: #{e}"
    exit -1
  end
end

.listObject

List all gill cloned repositories.



74
75
76
77
# File 'lib/gill/cli.rb', line 74

def CLI.list
  Gill.config.list_entries
  exit -1
end

.pull(args) ⇒ Object

CLI.Pull

Parameters:

  • args (String)

    Repository, folder name and/or repository name.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gill/cli.rb', line 22

def CLI.pull(args)
  begin
    require 'rubygems'
    require 'bundler'
    uri = Parse.new(args)
    git = Git.new(uri.category, uri.folder, uri.repo)
    git.clone
  rescue LoadError
    STDERR.puts "Count not load the bundler gem. Install it with 'gem install bundler'."
    exit -1
  rescue TypeError => e
    STDERR.puts "Error: #{e}"
  rescue => e
    STDERR.puts "Error: #{e}"
  end
end

.remove(repo_name) ⇒ Object

Remove a gill cloned repository.

Parameters:

  • args (String)

    The category and repository name to remove.



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gill/cli.rb', line 84

def CLI.remove(repo_name)
  begin

  Gill.config.find_repo_paths_by_name(repo_name, false) do |repo,path,category|
    Remove.new("#{category}##{repo}").remove_repo
  end

  rescue => e
    STDERR.puts "Error: #{e}"
    exit -1
  end
  exit -1
end

.update(repo_name) ⇒ Object

Update a gill repository.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gill/cli.rb', line 57

def CLI.update(repo_name)
  begin
    git = Git.new(false, repo_name, false)
    git.update
    exit -1
  rescue TypeError => e
    STDERR.puts "Error: #{e}\n"
    exit -1
  rescue => e
    STDERR.puts "Error: #{e}"
    exit -1
  end
end

Instance Method Details

#optparse(*args) ⇒ Object

Gill option parser

Parameters:

  • passed (Array)

    gill options.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/gill/cli.rb', line 100

def optparse(*args)

  @opts = OptionParser.new

  @options = {}

  @opts.banner = "Gill - Git, Clone, Cleanliness.\nUsage: gill git://host/repository.git#category/sub-category/...\n\n"

  @opts.on('-l','--list','List all cloned repositories.') do |list|
    CLI.list
  end

  @opts.on('-p ','--path ','Ouput the path of a repository. e.g. --path gill') do |repo_name|
    Gill.config.find_repo_paths_by_name(repo_name)
    exit -1
  end

  @opts.on('-r ','--remove ','Remove repository. e.g. -r category#repository') do |remove|
    CLI.remove(remove)
  end

  @opts.on('-u ', '--update ','Update repository. e.g. -u *gill*') do |update|
    CLI.update(update)
  end

  @opts.on('-i','--import','Import untracked repositories.') do |import|
    CLI.import
  end

  @opts.on('-h','--help','This help summary page.') do |help|
    usage
  end

  @opts.on('-v','--version','Version number') do |version|
    STDOUT.puts "Version: #{Gill::VERSION}"
    exit -1
  end

  begin
    @args = @opts.parse!(args)
    usage if @args.empty? || @args[0].nil?
    CLI.pull(@args[0])
  rescue Interrupt
    STDERR.puts "\nExiting..."
  rescue OptionParser::MissingArgument => e
    STDERR.puts e.message
    STDOUT.puts @opts
    STDOUT.puts "\n"
    exit -1
  rescue OptionParser::InvalidOption => e
    STDERR.puts e.message
    STDOUT.puts @opts
    STDOUT.puts "\n"
    exit -1
  end
end

#usageString

Gill usage.

Returns:

  • (String)

    Gill Usage Information.



161
162
163
164
# File 'lib/gill/cli.rb', line 161

def usage
  STDOUT.puts "#{@opts}\n"
  exit -1
end