Skip to content

Latest commit

 

History

History

commands-nested

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Sub-Commands Example

Demonstrates how to commands can be nested inside other commands.

This example was generated with:

$ bashly init
# ... now edit src/bashly.yml to match the example ...
$ bashly generate

bashly.yml

name: cli
help: Sample application with nested commands
version: 0.1.0

commands:
- name: dir
  alias: d
  help: Directory commands

  # The `commands` array can be nested inside any other command
  # This particular array will generate a script that answers to
  # `cli dir list` and `cli dir remove`
  commands:
  - name: list
    help: Show files in the directory

    args: &dir_args
    - name: path
      help: Directory path
      required: true

  - name: remove
    help: Remove directory
    args: *dir_args   # reuse args from the list command

    flags:
    - long: --force
      short: -f
      help: Remove even if when not empty

- name: file
  alias: f
  help: File commands

  # The nested commands for `cli file` - will generate `cli file show` and
  # `cli file edit`.
  commands:
  - name: show
    help: Show file contents
    args: &file_args
    - name: path
      help: Path to file
      required: true

  - name: edit
    help: Edit the file
    args: *file_args   # reuse args from the show command

Output

$ ./cli

cli - Sample application with nested commands

Usage:
  cli COMMAND
  cli [COMMAND] --help | -h
  cli --version | -v

Commands:
  dir    Directory commands
  file   File commands


$ ./cli -h

cli - Sample application with nested commands

Usage:
  cli COMMAND
  cli [COMMAND] --help | -h
  cli --version | -v

Commands:
  dir    Directory commands
  file   File commands

Options:
  --help, -h
    Show this help

  --version, -v
    Show version number


$ ./cli dir

cli dir - Directory commands

Alias: d

Usage:
  cli dir COMMAND
  cli dir [COMMAND] --help | -h

Commands:
  list     Show files in the directory
  remove   Remove directory


$ ./cli file

cli file - File commands

Alias: f

Usage:
  cli file COMMAND
  cli file [COMMAND] --help | -h

Commands:
  show   Show file contents
  edit   Edit the file


$ ./cli dig

invalid command: dig

$ ./cli dir -h

cli dir - Directory commands

Alias: d

Usage:
  cli dir COMMAND
  cli dir [COMMAND] --help | -h

Commands:
  list     Show files in the directory
  remove   Remove directory

Options:
  --help, -h
    Show this help


$ ./cli file -h

cli file - File commands

Alias: f

Usage:
  cli file COMMAND
  cli file [COMMAND] --help | -h

Commands:
  show   Show file contents
  edit   Edit the file

Options:
  --help, -h
    Show this help


$ ./cli dir list

missing required argument: PATH
usage: cli dir list PATH

$ ./cli dir list -h

cli dir list - Show files in the directory

Usage:
  cli dir list PATH
  cli dir list --help | -h

Options:
  --help, -h
    Show this help

Arguments:
  PATH
    Directory path


$ ./cli dir lost -h

invalid command: lost

$ ./cli file edit

missing required argument: PATH
usage: cli file edit PATH

$ ./cli file edit -h

cli file edit - Edit the file

Usage:
  cli file edit PATH
  cli file edit --help | -h

Options:
  --help, -h
    Show this help

Arguments:
  PATH
    Path to file


$ ./cli file edit filename

# This file is located at 'src/file_edit_command.sh'.
# It contains the implementation for the 'cli file edit' command.
# The code you write here will be wrapped by a function named 'cli_file_edit_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[path]} = filename