README.md in cri-2.13.0 vs README.md in cri-2.14.0

- old
+ new

@@ -341,9 +341,67 @@ ```ruby default_subcommand 'compile' ``` +### Loading commands from separate files + +You can use `Cri::Command.load_file` to load a command from a file. + +For example, given the file _commands/check.rb_ with the following contents: + +```ruby +name 'check' +usage 'check' +summary 'runs all checks' +description '…' + +run do |opts, args, cmd| + puts "Running checks…" +end +``` + +To load this command: + +```ruby +Cri::Command.load_file('commands/check.rb') +``` + +`Cri::Command.load_file` expects the file to be in UTF-8. + +You can also use it to load subcommands: + +```ruby +root_cmd = Cri::Command.load_file('commands/nanoc.rb') +root_cmd.add_command(Cri::Command.load_file('commands/comile.rb')) +root_cmd.add_command(Cri::Command.load_file('commands/view.rb')) +root_cmd.add_command(Cri::Command.load_file('commands/check.rb')) +``` + +#### Automatically inferring command names + +Pass `infer_name: true` to `Cri::Command.load_file` to use the file basename as the name of the command. + +For example, given a file _commands/check.rb_ with the following contents: + +```ruby +usage 'check' +summary 'runs all checks' +description '…' + +run do |opts, args, cmd| + puts "Running checks…" +end +``` + +To load this command and infer the name: + +```ruby +cmd = Cri::Command.load_file('commands/check.rb', infer_name: true) +``` + +`cmd.name` will be `check`, derived from the filename. + ## Contributors * Bart Mesuere * Ken Coar * Tim Sharpe