command :publish do |c| c.syntax = 'brief publish PUBLISHER [options]' c.description = 'publish a brief file with whatever publisher template you want to use.' c.option '--from FILE', 'Specify a file to read from. Otherwise we use $EDITOR' c.action do |args, options| path = case when options.from Pathname(options.from) when (Pathname(args.last).exist? rescue false) Pathname(args.pop) end document = Brief::Document.new(path: path) publisher = if path && path.exist? && args.empty? guess = path.basename.to_s.gsub(/\.\w+$/,'') Brief::Publisher.find(guess) else Brief::Publisher.find(args) end document.publish(publisher) end end