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 ## # Short description of each command. def description; nil; end ## # :call-seq: # execute(Array, Hash) -> nil # # - Array: arguments for each command # - Hash : rbnotes configuration def execute(args, conf) Builtins.default_cmd.new.execute(args, conf) end ## # Shows the help message for the command. # def help Builtins::Usage.new.execute(nil, nil) 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 Usage < Command def description "Print usage" end def execute(_, _) puts < "20201106165115" "2020-11-06" -> "20201106000000" "20201106" -> "20201106000000" "2020-11-06 16" -> "20201106160000" "2020-11-06 16:51" -> "20201106165100" STAMP end end class Time < Command def description "Convert a timestamp into a time string" end def execute(args, _) stamp = args.shift unless stamp.nil? puts ::Time.new(*Textrepo::Timestamp.split_stamp(stamp).map(&:to_i)).to_s else puts "not specified STAMP" super end end def help puts <