Class: Packwerk::Cli
Overview
A command-line interface to Packwerk.
Instance Method Summary collapse
- #execute_command(args) ⇒ Object
-
#initialize(configuration: nil, out: $stdout, err_out: $stderr, environment: "test", style: OutputStyles::Plain.new, offenses_formatter: nil) ⇒ Cli
constructor
A new instance of Cli.
- #run(args) ⇒ Object
Constructor Details
#initialize(configuration: nil, out: $stdout, err_out: $stderr, environment: "test", style: OutputStyles::Plain.new, offenses_formatter: nil) ⇒ Cli
Returns a new instance of Cli.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/packwerk/cli.rb', line 19 def initialize( configuration: nil, out: $stdout, err_out: $stderr, environment: "test", style: OutputStyles::Plain.new, offenses_formatter: nil ) @out = out @err_out = err_out @environment = environment @style = style @configuration = T.let(configuration || Configuration.from_path, Configuration) @progress_formatter = T.let(Formatters::ProgressFormatter.new(@out, style: style), Formatters::ProgressFormatter) @offenses_formatter = T.let( offenses_formatter || @configuration.offenses_formatter, OffensesFormatter ) end |
Instance Method Details
#execute_command(args) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/packwerk/cli.rb', line 46 def execute_command(args) command = args.shift || "help" command_class = Commands.for(command) if command_class command_class.new( args, configuration: @configuration, out: @out, err_out: @err_out, progress_formatter: @progress_formatter, offenses_formatter: @offenses_formatter, ).run else @err_out.puts("'#{command}' is not a packwerk command. See `packwerk help`.",) false end end |
#run(args) ⇒ Object
40 41 42 43 |
# File 'lib/packwerk/cli.rb', line 40 def run(args) success = execute_command(args) exit(success) end |