Class: Rbnotes::Commands::Export
- Defined in:
- lib/rbnotes/commands/export.rb
Overview
Writes out a given note into a specified file. The file will be created in the current working directory unless an absolute path is specified as a filename.
When no argument was passed, would try to read a timestamp string from the standard input.
Instance Method Summary collapse
-
#description ⇒ Object
:nodoc:.
-
#execute(args, conf) ⇒ Object
:call-seq: execute([a String as timestring], Rbnotes::Conf or Hash) -> nil.
-
#help ⇒ Object
:nodoc:.
Instance Method Details
#description ⇒ Object
:nodoc:
15 16 17 |
# File 'lib/rbnotes/commands/export.rb', line 15 def description # :nodoc: "Write out a note into a file" end |
#execute(args, conf) ⇒ Object
:call-seq:
execute([a String as timestring], Rbnotes::Conf or Hash) -> nil
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rbnotes/commands/export.rb', line 23 def execute(args, conf) stamp = Rbnotes.utils.(args) args.shift # drop the 1st argument repo = Textrepo.init(conf) begin content = repo.read(stamp) rescue Textrepo::MissingTimestampError => _ raise MissingTimestampError, stamp end pathname = Pathname.new(args.shift || "#{stamp}.md") pathname.parent.mkpath pathname.open("w"){ |f| f.puts content } puts "Export a note [%s] into a file [%s]" % [stamp, pathname] end |
#help ⇒ Object
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rbnotes/commands/export.rb', line 40 def help # :nodoc: puts <<HELP usage: #{Rbnotes::NAME} export [TIMESTAMP [FILENAME]] Write out a given note into a specified file. TIMESTAMP must be a fully qualified one, such "20201108141600", or "20201108141600_012" if it has a suffix. FILENAME is optional. When it omitted, the filename would be a timestamp string with ".md" as its extension, such "20201108141600.md" The file will be created into the current working directory unless an absolute path is specified as FILENAME. When no argument was passed, it would try to read a timestamp string from the standard input. Then, FILENAME would be regarded as omitted. HELP end |