class Kontena::Plugin::Shell::Command
Attributes
args[R]
context[R]
session[R]
Public Class Methods
command(name = nil)
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 7 def self.command(name = nil) return @command if instance_variable_defined?(:@command) disabled_commands = ENV['KOSH_DISABLED_COMMANDS'].to_s.split(/,/) Array(name).each { |name| Shell.commands[name] = self unless disabled_commands.include?(name) } @command = name end
completions(*completions)
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 40 def self.completions(*completions) @completions ||= completions end
description(text = nil)
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 32 def self.description(text = nil) @description ||= text end
has_subcommands?()
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 24 def self.has_subcommands? !subcommands.nil? && !subcommands.empty? end
help(text = nil)
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 36 def self.help(text = nil) @help ||= text end
new(context = nil, args = nil, session = nil)
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 44 def initialize(context = nil, args = nil, session = nil) @args = Array(args) @context = context @session = session end
subcommands(subcommands = nil)
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 14 def self.subcommands(subcommands = nil) return @subcommands if instance_variable_defined?(:@subcommands) @subcommands = {} Array(subcommands).each do |sc| Array(sc.command).each do |name| @subcommands[name] = sc end end end
Public Instance Methods
has_subcommands?()
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 28 def has_subcommands? self.class.has_subcommands? end
run()
click to toggle source
# File lib/kontena/plugin/shell/command.rb, line 50 def run if has_subcommands? if args[1] subcommand = self.class.subcommands[args[1]] if subcommand subcommand.new(context, args[1..-1], session).run else puts Kontena.pastel.red("Unknown subcommand") end else context << args[0] end else execute end rescue Kontena::Plugin::Shell::ExitCommand::CleanExit puts Kontena.pastel.green("Bye!") exit 0 rescue => ex puts Kontena.pastel.red("ERROR: " + ex.message) puts Kontena.pastel.green(ex.backtrace.join("\n ")) if ENV["DEBUG"] end