lib/hx/cli.rb in hx-0.8.2 vs lib/hx/cli.rb in hx-0.8.3
- old
+ new
@@ -40,10 +40,11 @@
opts.banner = <<EOS
Usage: hx [--config CONFIG_FILE] [upgen]
hx [--config CONFIG_FILE] regen
hx [--config CONFIG_FILE] post[up] SOURCE:PATH
hx [--config CONFIG_FILE] edit[up] SOURCE:PATH
+ hx [--config CONFIG_FILE] list SOURCE:PATTERN
EOS
opts.on("-c", "--config CONFIG_FILE",
"Use CONFIG_FILE instead of searching for " +
@@ -126,34 +127,50 @@
def self.cmd_postup(site, entry_spec)
cmd_post(site, entry_spec)
cmd_upgen(site)
end
-def self.parse_entry_spec(entry_spec)
+def self._parse_entry_spec(site, entry_spec)
source_name, path = entry_spec.split(':', 2)
+ source = site.sources[source_name]
+ raise ArgumentError, "No such source #{source_name}" unless source
+ return source, path
+end
+
+def self.parse_entry_spec(site, entry_spec)
+ source, path = _parse_entry_spec(site, entry_spec)
raise "Invalid entry specification #{entry_spec}" unless path
- return source_name, path
+ return source, path
end
+def self.parse_entry_pattern(site, entry_pattern)
+ source, pattern = _parse_entry_spec(site, entry_pattern)
+ pattern = "**" unless pattern
+ selector = Hx::Path.parse_pattern(pattern)
+ return source, selector
+end
+
def self.cmd_edit(site, entry_spec)
- source_name, path = parse_entry_spec(entry_spec)
- do_edit(site, source_name, path, nil)
+ source, path = parse_entry_spec(site, entry_spec)
+ do_edit(site, source, path, nil)
end
def self.cmd_post(site, entry_spec)
- source_name, path = parse_entry_spec(entry_spec)
+ source, path = parse_entry_spec(site, entry_spec)
prototype = {
'title' => Hx.make_default_title(site.options, path),
'author' => Hx.get_default_author(site.options),
'content' => ""
}
- do_edit(site, source_name, path, prototype)
+ do_edit(site, source, path, prototype)
end
-def self.do_edit(site, source_name, path, prototype)
- source = site.sources[source_name]
- raise ArgumentError, "No such source #{source_name}" unless source
+def self.cmd_list(site, entry_spec)
+ source, selector = parse_entry_pattern(site, entry_spec)
+ source.each_entry_path(selector) { |path| puts path }
+end
+def self.do_edit(site, source, path, prototype)
catch(:unchanged) do
begin
tempfile = Tempfile.new('hx-entry')
original_text = nil
loop do