Class: Octopress::Unpublish

Inherits:
Command
  • Object
show all
Defined in:
lib/octopress/commands/unpublish.rb

Class Method Summary collapse

Methods inherited from Command

inherited, #init_with_program, subclasses

Class Method Details

.init_with_program(p) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/octopress/commands/unpublish.rb', line 3

def self.init_with_program(p)
  p.command(:unpublish) do |c|
    c.syntax 'unpublish <POST> [options]'
    c.option 'force', '--force', 'Overwrite draft if it already exists'
    c.description 'Convert a post to a draft. Command accepts path to post or search string.'
    CommandHelpers.add_common_options c

    c.action do |args, options|
      options['path'] = args.first
      options['type'] = 'draft from post'

      if !options['path']
        abort "Unpublish failed: Please provide a path or a search string to select your post."
      end
      if File.exist?(options['path'])
        unpublish_post(options)
      else
        options['path'] = CommandHelpers.select_posts(options['path'], 'unpublish')
        unpublish_post(options)
      end
    end
  end
end

.unpublish_post(options) ⇒ Object



27
28
29
# File 'lib/octopress/commands/unpublish.rb', line 27

def self.unpublish_post(options)
  Post.new(Octopress.site(options), options).unpublish
end