Class: Packwerk::Cli
- Inherits:
-
Object
- Object
- Packwerk::Cli
- Defined in:
- lib/packwerk/cli.rb
Overview
A command-line interface to Packwerk.
Instance Method Summary collapse
-
#execute_command(args) ⇒ Object
: (Array args) -> bool.
-
#initialize(configuration: nil, out: $stdout, err_out: $stderr, environment: "test", style: OutputStyles::Plain.new, offenses_formatter: nil) ⇒ Cli
constructor
: ( | ?configuration: Configuration?, | ?out: (StringIO | IO), | ?err_out: (StringIO | IO), | ?environment: String, | ?style: OutputStyle, | ?offenses_formatter: OffensesFormatter? | ) -> void.
-
#run(args) ⇒ Object
: (Array args) -> bot.
Constructor Details
#initialize(configuration: nil, out: $stdout, err_out: $stderr, environment: "test", style: OutputStyles::Plain.new, offenses_formatter: nil) ⇒ Cli
: ( | ?configuration: Configuration?, | ?out: (StringIO | IO), | ?err_out: (StringIO | IO), | ?environment: String, | ?style: OutputStyle, | ?offenses_formatter: OffensesFormatter? | ) -> void
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/packwerk/cli.rb', line 15 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 = configuration || Configuration.from_path #: Configuration @progress_formatter = Formatters::ProgressFormatter.new(@out, style: style) #: Formatters::ProgressFormatter @offenses_formatter = offenses_formatter || @configuration.offenses_formatter #: OffensesFormatter end |
Instance Method Details
#execute_command(args) ⇒ Object
: (Array args) -> bool
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/packwerk/cli.rb', line 39 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
: (Array args) -> bot
33 34 35 36 |
# File 'lib/packwerk/cli.rb', line 33 def run(args) success = execute_command(args) exit(success) end |