Class: Nanoc3::CLI::Commands::CreateItem
- Inherits:
-
Cri::Command
- Object
- Cri::Command
- Nanoc3::CLI::Commands::CreateItem
- Defined in:
- lib/nanoc3/cli/commands/create_item.rb
Instance Method Summary (collapse)
- - (Object) aliases
- - (Object) long_desc
- - (Object) name
- - (Object) option_definitions
- - (Object) run(options, arguments)
- - (Object) short_desc
- - (Object) usage
Instance Method Details
- (Object) aliases
11 12 13 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 11 def aliases [ 'ci' ] end |
- (Object) long_desc
19 20 21 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 19 def long_desc 'Create a new item in the current site. The first data source in the site configuration will be used.' end |
- (Object) name
7 8 9 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 7 def name 'create_item' end |
- (Object) option_definitions
27 28 29 30 31 32 33 34 35 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 27 def option_definitions [ # --vcs { :long => 'vcs', :short => 'c', :argument => :required, :desc => 'select the VCS to use' } ] end |
- (Object) run(options, arguments)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 37 def run(, arguments) # Check arguments if arguments.length != 1 $stderr.puts "usage: #{usage}" exit 1 end # Extract arguments and options identifier = arguments[0].cleaned_identifier # Make sure we are in a nanoc site directory @base.require_site @base.site.load_data # Set VCS if possible @base.set_vcs([:vcs]) # Check whether item is unique if !@base.site.items.find { |i| i.identifier == identifier }.nil? $stderr.puts "An item already exists at #{identifier}. Please " + "pick a unique name for the item you are creating." exit 1 end # Setup notifications Nanoc3::NotificationCenter.on(:file_created) do |file_path| Nanoc3::CLI::Logger.instance.file(:high, :create, file_path) end # Create item data_source = @base.site.data_sources[0] data_source.create_item( "Hi, I'm a new item!\n", { :title => "A New Item" }, identifier ) puts "An item has been created at #{identifier}." end |
- (Object) short_desc
15 16 17 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 15 def short_desc 'create a item' end |
- (Object) usage
23 24 25 |
# File 'lib/nanoc3/cli/commands/create_item.rb', line 23 def usage "nanoc3 create_item [options] identifier" end |