-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,019 additions
and
1,188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,191 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: utf-8 | ||
|
||
require_relative '../lib/diggit_cli.rb' | ||
require 'gli' | ||
require_relative '../lib/dgit' | ||
|
||
Diggit::Cli::DiggitCli.start(ARGV) | ||
include GLI::App | ||
|
||
program_desc 'A git repository analysis tool.' | ||
|
||
version Diggit::VERSION | ||
|
||
subcommand_option_handling :normal | ||
arguments :strict | ||
|
||
desc 'Init a diggit folder.' | ||
skips_pre | ||
command :init do |c| | ||
c.action do |_global_options, _options, _args| | ||
Diggit::Dig.init_dir | ||
Log.ok "Diggit folder initialized." | ||
end | ||
end | ||
|
||
desc 'Display the status of the diggit folder.' | ||
command :status do |c| | ||
c.action do |_global_options, _options, _args| | ||
Log.info "Config" | ||
Log.info "======" | ||
Log.info "- Analyses: #{Diggit::Dig.it.config.get_analyses.join(', ')}" | ||
Log.info "- Joins: #{Diggit::Dig.it.config.get_joins.join(', ')}" | ||
Log.info "" | ||
Log.info "Journal" | ||
Log.info "=======" | ||
Log.info "- New sources:" | ||
Log.indent do | ||
Log.ok "* Ok: #{Diggit::Dig.it.journal.sources_by_state(:new).size}" | ||
Log.error "* Error: #{Diggit::Dig.it.journal.sources_by_state(:new, true).size}" | ||
end | ||
Log.info "- Cloned sources:" | ||
Log.indent do | ||
Log.ok "* Ok: #{Diggit::Dig.it.journal.sources_by_state(:cloned).size}" | ||
Log.error "* Error: #{Diggit::Dig.it.journal.sources_by_state(:cloned, true).size}" | ||
end | ||
end | ||
end | ||
|
||
desc 'Manage the sources of the diggit folder.' | ||
command :sources do |c| | ||
c.desc 'List the sources.' | ||
c.command :list do |list| | ||
list.action do |_global_options, _options, _args| | ||
sources = Diggit::Dig.it.journal.sources | ||
sources.each_index do |idx| | ||
msg = "#{idx} #{sources[idx].url} (#{sources[idx].state})" | ||
sources[idx].error? ? Log.error(msg) : Log.ok(msg) | ||
end | ||
end | ||
end | ||
c.desc 'Add a source.' | ||
c.arg_name 'url' | ||
c.command :add do |add| | ||
add.action do |_global_options, _options, args| | ||
Diggit::Dig.it.journal.add_source args[0] | ||
end | ||
end | ||
c.desc 'Import sources from a file.' | ||
c.arg_name 'file' | ||
c.command :import do |import| | ||
import.action do |_global_options, _options, args| | ||
File.open(args[0]).each { |line| Diggit::Dig.it.journal.add_source(line) } | ||
end | ||
end | ||
c.default_command :list | ||
end | ||
|
||
desc 'Manage the joins of the diggit folder.' | ||
command :joins do |c| | ||
c.desc 'List the joins' | ||
c.command :list do |list| | ||
list.action do |_global_options, _options, _args| | ||
Diggit::Dig.it.config.get_joins.each { |a| Log.info a.name } | ||
end | ||
end | ||
c.desc 'Add add join.' | ||
c.arg_name 'name' | ||
c.command :add do |add| | ||
add.action do |_global_options, _options, args| | ||
Diggit::Dig.it.config.add_join args[0] | ||
end | ||
end | ||
c.desc 'Perform joins.' | ||
c.command :perform do |perform| | ||
perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: [] | ||
perform.flag [:a, :analyses], desc: "list of analyses", type: Array, default_value: [] | ||
perform.flag [:m, :mode], desc: "running mode", | ||
must_match: { "run" => :run, "clean" => :clean, "rerun" => :rerun }, default_value: :run | ||
perform.action do |_global_options, options, _args| | ||
Diggit::Dig.it.join(options[:s], options[:a], options[:m]) | ||
end | ||
end | ||
c.default_command :list | ||
end | ||
|
||
desc 'Manage the analyses of the diggit folder.' | ||
command :analyses do |c| | ||
c.desc 'List the analyses' | ||
c.command :list do |list| | ||
list.action do |_global_options, _options, _args| | ||
Diggit::Dig.it.config.get_analyses.each { |a| Log.info a.name } | ||
end | ||
end | ||
c.desc 'Add an analysis.' | ||
c.arg_name 'name' | ||
c.command :add do |add| | ||
add.action do |_global_options, _options, args| | ||
Diggit::Dig.it.config.add_analysis args[0] | ||
end | ||
end | ||
c.desc 'Perform analyses.' | ||
c.command :perform do |perform| | ||
perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: [] | ||
perform.flag [:a, :analyses], desc: "list of analyses", type: Array, default_value: [] | ||
perform.flag [:m, :mode], desc: "running mode", | ||
must_match: { "run" => :run, "clean" => :clean, "rerun" => :rerun }, default_value: :run | ||
perform.action do |_global_options, options, _args| | ||
Diggit::Dig.it.analyze(options[:s], options[:a], options[:m]) | ||
end | ||
end | ||
c.default_command :list | ||
end | ||
|
||
desc 'Manage clone actions.' | ||
command :clone do |c| | ||
c.desc 'Perform the clones.' | ||
c.command :perform do |perform| | ||
perform.flag [:s, :sources], desc: "list of sources", type: Array, default_value: [] | ||
perform.action do |_global_options, options, _args| | ||
Diggit::Dig.it.clone(*options[:s]) | ||
end | ||
end | ||
c.default_command :perform | ||
end | ||
|
||
desc 'Display errors.' | ||
command :errors do |c| | ||
c.desc 'Display the list of errors.' | ||
c.command :list do |list| | ||
list.action do |_global_options, _options, _args| | ||
sources = Diggit::Dig.it.journal.sources | ||
sources.each_index do |idx| | ||
msg = "#{idx} #{sources[idx].url} (#{sources[idx].state})" | ||
Log.error msg if sources[idx].error? | ||
end | ||
end | ||
end | ||
c.desc 'Display a source error.' | ||
c.arg_name 'id' | ||
c.command :show do |show| | ||
show.action do |_global_options, _options, args| | ||
source = Diggit::Dig.it.journal.sources_by_ids(args[0].to_i)[0] | ||
Log.ok "Error summary for source #{args[0]}" | ||
error = source.error | ||
Log.info "URL: #{source.url}" | ||
Log.info "State: #{source.state}" | ||
Log.info "Error:" | ||
Log.indent do | ||
Log.error error[:message] | ||
Log.info error[:backtrace].join("\n") | ||
end | ||
end | ||
end | ||
c.default_command :list | ||
end | ||
|
||
pre do |_global, _command, _options, _args| | ||
Diggit::Dig.init | ||
end | ||
|
||
post do |_global, _command, _options, _args| | ||
# Post logic here, skips_post to skip commands | ||
end | ||
|
||
on_error do |exception| | ||
Log.error "Error running diggit." | ||
Log.error exception.message | ||
Log.info exception.backtrace.join("\n") | ||
false | ||
end | ||
|
||
exit run(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.