@@ -3,7 +3,7 @@ module Commands
33 class Publish < Command
44 def self . init_with_program ( prog )
55 prog . command ( :publish ) do |c |
6- c . syntax 'publish NAME '
6+ c . syntax 'publish DRAFT_PATH '
77 c . description 'Moves a draft into the _posts directory and sets the date'
88
99 c . option 'date' , '-d DATE' , '--date DATE' , 'Specify the post date'
@@ -15,16 +15,18 @@ def self.init_with_program(prog)
1515 end
1616
1717 def self . process ( args , options = { } )
18- raise ArgumentError . new ( 'You must specify a name .' ) if args . empty?
19-
18+ raise ArgumentError . new ( 'You must specify a draft path .' ) if args . empty?
19+
2020 date = options [ "date" ] . nil? ? Date . today : Date . parse ( options [ "date" ] )
21- file = args . shift
21+ draft_path = args . shift
22+
23+ raise ArgumentError . new ( "There was no draft found at '#{ draft_path } '." ) unless File . exist? draft_path
2224
23- post_path = post_name ( date , file )
24- FileUtils . mv ( draft_name ( file ) , post_path )
25+ post_path = post_name ( date , draft_name ( draft_path ) )
26+ FileUtils . mv ( draft_path , post_path )
2527
26- puts "Draft #{ file } was published to ./#{ post_path } "
27- end
28+ puts "Draft #{ draft_path } was published to ./#{ post_path } "
29+ end
2830
2931 # Internal: Gets the filename of the post to be created
3032 #
@@ -33,8 +35,8 @@ def self.post_name(date, name)
3335 "_posts/#{ date . strftime ( '%Y-%m-%d' ) } -#{ name } "
3436 end
3537
36- def self . draft_name ( name )
37- "_drafts/ #{ name } "
38+ def self . draft_name ( path )
39+ File . basename ( path )
3840 end
3941
4042 end
0 commit comments