Class: Sharekit::Cli::App

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

Overview

Thor gives us subcommand dispatch, flag parsing, and --help for free — the TS original hand-parses process.argv/flags itself.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


18
# File 'lib/sharekit/cli.rb', line 18

def self.exit_on_failure? = true

Instance Method Details

#init(*skill_names) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/sharekit/cli.rb', line 48

def init(*skill_names)
  result = Init.call(profile_dir: options[:dir], skill_names:, force: options[:force])
  print_init_summary(result)
  Reporter.report(result.findings, force: options[:force])
rescue Error => e
  warn e.message
  exit 1
end

#scan(dir = ".") ⇒ Object



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

def scan(dir = ".")
  findings = FileLister.list(dir).flat_map do |path|
    Scanner.scan(File.read(path, encoding: "UTF-8"), file: path).to_a
  rescue ArgumentError, Errno::ENOENT, Errno::EACCES => e
    puts "    ~ Skipped #{path}: #{e.class}"
    []
  end

  Reporter.report(findings, force: options[:force])
rescue Error => e
  warn e.message
  exit 1
end