module Rbnotes ## # This module defines all command classes of rbnotes. Each command # class must be derived from Rbnotes::Commands::Command class. module Commands ## # The base class for a command class. class Command ## # :call-seq: # Array, Hash -> nil # - Array: arguments for each command # - Hash : rbnotes configuration # def execute(args, conf) Builtins::DEFAULT_CMD.new.execute(args, conf) end end # :stopdoc: # Built-in commands: # - repo: prints the absolute path of the repository. # - conf: prints all of the current configuration settings. # - stamp: converts given TIME_STR into a timestamp. # - time: converts given STAMP into a time string. module Builtins class Help < Command def execute(_, _) puts < an object of Rbnotes::Commnads::Import # "list" -> an object of Rbnotes::Commands::List # "show" -> an object of Rbnotes::Commands::Show # def load(cmd_name) cmd_name ||= DEFAULT_CMD_NAME klass_name = cmd_name.capitalize klass = nil if Builtins.const_defined?(klass_name, false) klass = Builtins::const_get(klass_name, false) else begin require_relative "commands/#{cmd_name}" klass = const_get(klass_name, false) rescue LoadError => _ STDERR.puts "unknown command: #{cmd_name}" klass = Builtins::DEFAULT_CMD end end klass.new end end end end