-
Notifications
You must be signed in to change notification settings - Fork 8
CMUX Extension
Jon Kwon edited this page Jun 7, 2017
·
1 revision
Write command class file like $CMUX_HOME/ext/example.rb
and store into $CMUX_HOME/ext
.
$CMUX_HOME/ext/example.rb
#!/usr/bin/env ruby
module CMUX
module Commands
class Example
CMD = 'example' # command name
ALIAS = 'exam' # command alias
DESC = 'Example command' # command description
extend Commands
# Regist command.
reg_cmd(cmd: CMD, alias: ALIAS, desc: DESC)
# Initialize command.
def initialize(*args)
@args = *args
chk_opt
end
# Command process.
def process
puts "Hello CMUX"
end
# Regist and check command option.
# See $CMUX_HOME/lib/cmux/utils/opt_parser.rb
def chk_opt
opt = Utils::Checker::OptParser.new
banner = 'Usage: cmux COMMAND [OPTIONS]'
opt.banner(CMD, ALIAS, banner)
opt.separator('Options:')
opt.help_option
opt.parse
end
end
end
end
$ cmux exam
Hello CMUX
$CMUX_HOME/ext/example2.rb
#!/usr/bin/env ruby
module CMUX
module Commands
class ExampleForMe < Example
DESC = '[For me]Example command' # command description
# Regist command.
reg_cmd(cmd: CMD, alias: ALIAS, desc: DESC)
# Command process.
def process
puts "Hello my CMUX" # ======> extended
puts "Hello CMUX"
end
end
end
end
$ cmux exam
Hello my CMUX
Hello CMUX