Class: GitMarshal::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/gitmarshal/cli.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &_block) ⇒ Object (private)



186
187
188
189
190
191
192
193
194
# File 'lib/gitmarshal/cli.rb', line 186

def method_missing(method, *args, &_block)
  if method =~ /[-a-zA-Z0-9_.]+/
    today_option = args.include?("-t") ? args.include?("-t") : args.include?("--today")
    commit_history_option = args.include?("-ch") ? args.include?("-ch") : args.include?("--commit-history")
    metrics(method.to_s, today_option, commit_history_option)
  else
    super
  end
end

Instance Method Details

#helpObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gitmarshal/cli.rb', line 49

def help(*)
  rows = []
  rows << ["gitmarshal", " ", "Display all repositories associated with the authenticated user."]
  rows << ["gitmarshal repo-name", " ", "Display the overall metrics for the specified repository."]
  rows << ["gitmarshal repo-name", "-t", "Display the current day's metrics for the specified repository."]
  rows << ["gitmarshal repo-name", "-ch", "Display the commit history grouped by days for the given repository."]

  table = Terminal::Table.new :rows => rows
  table.title = "GitMarshal Commands".colorize(:blue).bold
  table.headings = ["Command", "Options", "Description"].map { |i| i.colorize(:magenta).bold }
  table.style = { :border_x => "=", :border_i => "x", :alignment => :left }
  puts table
end

#reposObject



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
# File 'lib/gitmarshal/cli.rb', line 21

def repos
  begin
    fetcher = GithubFetcher.new
    user = fetcher.fetch_user
    repos = fetcher.fetch_repos

    puts "GitHub Repositories for #{user}".colorize(:blue).bold

    rows = repos.map do |repo|
      [
        repo["name"],
        repo["issues"],
        repo["stargazers"],
        repo["forks"],
      ]
    end

    table = Terminal::Table.new :title => "Repositories".colorize(:blue).bold,
                                :headings => ["Name", "Issues", "Stargazers", "Forks"].map { |i| i.colorize(:magenta).bold },
                                :rows => rows

    table.style = { :border_x => "=", :border_i => "x", :alignment => :center }
    puts table
  rescue StandardError => e
    puts "An error occurred: #{e.message}"
  end
end

#versionObject



16
17
18
# File 'lib/gitmarshal/cli.rb', line 16

def version
  puts "GitMarshal Version #{Gitmarshal::VERSION}"
end