Module: Arborist::CLI::Subcommand

Included in:
Ack, Client, Config, Reset, RunOnce, Start, Summary, Tree, Watch
Defined in:
lib/arborist/cli.rb

Overview

Convenience module for subcommand registration syntax sugar.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.display_table(header, rows) ⇒ Object

Output a table with the given header (an array) and rows (an array of arrays).



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/arborist/cli.rb', line 343

def display_table( header, rows )
	table = TTY::Table.new( header, rows )
	renderer = nil

	if hl.enabled?
		renderer = TTY::Table::Renderer::Unicode.new(
			table,
			multiline: true,
			padding: [0,1,0,1]
		)
		renderer.border.style = :dim

	else
		renderer = TTY::Table::Renderer::ASCII.new(
			table,
			multiline: true,
			padding: [0,1,0,1]
		)
	end

	puts renderer.render
end

.error_string(string) ⇒ Object

Return the specified string in the ‘error’ ANSI color.



336
337
338
# File 'lib/arborist/cli.rb', line 336

def error_string( string )
	return hl.error( string )
end

.exit_now!(message, exit_code = 1) ⇒ Object

Exit with the specified exit_code after printing the given message.

Raises:

  • (GLI::CustomExit)


291
292
293
# File 'lib/arborist/cli.rb', line 291

def exit_now!( message, exit_code=1 )
	raise GLI::CustomExit.new( message, exit_code )
end

.extended(mod) ⇒ Object

Extension callback – register the extending object as a subcommand.



256
257
258
259
# File 'lib/arborist/cli.rb', line 256

def self::extended( mod )
	Arborist::CLI.log.debug "Registering subcommands from %p" % [ mod ]
	Arborist::CLI.register_subcommands( mod )
end

.headline_string(string) ⇒ Object

Return the specified string in the ‘headline’ ANSI color.



318
319
320
# File 'lib/arborist/cli.rb', line 318

def headline_string( string )
	return hl.headline( string )
end

.help_now!(message = nil) ⇒ Object

Exit with a helpful message and display the usage.



297
298
299
300
301
302
# File 'lib/arborist/cli.rb', line 297

def help_now!( message=nil )
	exception = OptionParser::ParseError.new( message )
	def exception.exit_code; 64; end

	raise exception
end

.highlight_string(string) ⇒ Object

Return the specified string in the ‘highlight’ ANSI color.



324
325
326
# File 'lib/arborist/cli.rb', line 324

def highlight_string( string )
	return hl.highlight( string )
end

.hlObject

Return the global Pastel object for convenient formatting, color, etc.



312
313
314
# File 'lib/arborist/cli.rb', line 312

def hl
	return Arborist::CLI.pastel
end

.promptObject

Get the prompt (a TTY::Prompt object)



306
307
308
# File 'lib/arborist/cli.rb', line 306

def prompt
	return Arborist::CLI.prompt
end

.success_string(string) ⇒ Object

Return the specified string in the ‘success’ ANSI color.



330
331
332
# File 'lib/arborist/cli.rb', line 330

def success_string( string )
	return hl.success( string )
end

.unless_dryrun(description, return_value = true) ⇒ Object Also known as: unless_dry_run

In dry-run mode, output the description instead of running the provided block and return the return_value. If dry-run mode is not enabled, yield to the block.



376
377
378
379
380
381
382
383
# File 'lib/arborist/cli.rb', line 376

def unless_dryrun( description, return_value=true )
	if $DRYRUN
		self.log.warn( "DRYRUN> #{description}" )
		return return_value
	else
		return yield
	end
end

.visible_chars(string) ⇒ Object

Return the count of visible (i.e., non-control) characters in the given string.



368
369
370
# File 'lib/arborist/cli.rb', line 368

def visible_chars( string )
	return string.to_s.gsub(/\e\[.*?m/, '').scan( /\P{Cntrl}/ ).size
end

Instance Method Details

#skips_aroundObject

Use this if the following command should not have the around block executed. By default, the around block is executed, but for commands that might not want the setup to happen, this can be handy



281
282
283
# File 'lib/arborist/cli.rb', line 281

def skips_around
	@skips_around = true
end

#skips_postObject

Use this if the following command should not have the post block executed. By default, the post block is executed after each command. Using this will avoid that behavior for the following command



273
274
275
# File 'lib/arborist/cli.rb', line 273

def skips_post
	@skips_post = true
end

#skips_preObject

Use this if the following command should not have the pre block executed. By default, the pre block is executed before each command and can result in aborting the call. Using this will avoid that behavior for the following command



265
266
267
# File 'lib/arborist/cli.rb', line 265

def skips_pre
	@skips_pre = true
end