Class: DNote::Options
- Inherits:
-
Object
- Object
- DNote::Options
- Defined in:
- lib/dnote/options.rb
Overview
Option parser
Class Method Summary collapse
Instance Method Summary collapse
- #add_command_options(session, opt) ⇒ Object
- #add_other_options(session, opt) ⇒ Object
- #add_output_format_options(session, opt) ⇒ Object
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #parse ⇒ Object
Constructor Details
#initialize(argv) ⇒ Options
Returns a new instance of Options.
15 16 17 |
# File 'lib/dnote/options.rb', line 15 def initialize(argv) @argv = argv end |
Class Method Details
.parse(*argv) ⇒ Object
11 12 13 |
# File 'lib/dnote/options.rb', line 11 def self.parse(*argv) new(argv).parse end |
Instance Method Details
#add_command_options(session, opt) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dnote/options.rb', line 38 def (session, opt) opt.separator(" ") opt.separator("COMMAND OPTIONS:") opt.on_tail("--templates", "-T", "list available format templates") do session.list_templates exit end opt.on_tail("--help", "-h", "show this help information") do puts opt exit end end |
#add_other_options(session, opt) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/dnote/options.rb', line 75 def (session, opt) opt.separator(" ") opt.separator("OTHER OPTIONS:") opt.on("--label", "-l LABEL", "labels to collect") do |lbl| session.labels.concat(lbl.split(":")) end opt.on(:colon, "--[no-]colon", "match labels with/without colon suffix") do |val| session.colon = val end opt.on("--marker", "-m MARK", "alternative remark marker") do |mark| session.marker = mark end opt.on("--url", "-u TEMPLATE", "url template for line entries (for HTML)") do |url| session.url = url end opt.on("--context", "-c INTEGER", "number of lines of context to display") do |int| session.context = int.to_i end opt.on("--exclude", "-x PATH", "exclude file or directory") do |path| session.exclude << path end opt.on("--ignore", "-i NAME", "ignore file based on any part of pathname") do |name| session.ignore << name end opt.on("--title", "-t TITLE", "title to use in header") do |title| session.title = title end opt.on("--output", "-o PATH", "save to file or directory") do |path| session.output = path end opt.on("--dryrun", "-n", "do not actually write to disk") do session.dryrun = true end opt.on("--debug", "debug mode") do $DEBUG = true $VERBOSE = true end end |
#add_output_format_options(session, opt) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dnote/options.rb', line 53 def (session, opt) opt.separator(" ") opt.separator("OUTPUT FORMAT: (choose one)") opt.on("--format", "-f NAME", "select a format [text]") do |format| session.format = format end opt.on("--custom", "-C FILE", "use a custom ERB template") do |file| session.format = "custom" session.template = file end opt.on("--file", "shortcut for text/file format") do session.format = "text/file" end opt.on("--list", "shortcut for text/list format") do session.format = "text/list" end end |
#parse ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dnote/options.rb', line 19 def parse session = Session.new opts = OptionParser.new do |opt| opt. = "DNote v#{DNote::VERSION}" opt.separator(" ") opt.separator("USAGE:\n dnote [OPTIONS] path1 [path2 ...]") (session, opt) (session, opt) (session, opt) end opts.parse!(@argv) session.paths.replace(@argv) session end |