| 1 | module cli |
| 2 | |
| 3 | fn test_help_message() { |
| 4 | mut cmd := Command{ |
| 5 | name: 'command' |
| 6 | description: 'description' |
| 7 | commands: [ |
| 8 | Command{ |
| 9 | name: 'sub' |
| 10 | description: 'subcommand' |
| 11 | }, |
| 12 | Command{ |
| 13 | name: 'sub2' |
| 14 | description: 'another subcommand' |
| 15 | }, |
| 16 | ] |
| 17 | flags: [ |
| 18 | Flag{ |
| 19 | flag: .string |
| 20 | name: 'str' |
| 21 | description: 'str flag' |
| 22 | }, |
| 23 | Flag{ |
| 24 | flag: .bool |
| 25 | name: 'bool' |
| 26 | description: 'bool flag' |
| 27 | abbrev: 'b' |
| 28 | }, |
| 29 | Flag{ |
| 30 | flag: .string |
| 31 | name: 'required' |
| 32 | abbrev: 'r' |
| 33 | required: true |
| 34 | }, |
| 35 | ] |
| 36 | } |
| 37 | assert cmd.help_message() == r'Usage: command [flags] [commands] |
| 38 | |
| 39 | description |
| 40 | |
| 41 | Flags: |
| 42 | -str str flag |
| 43 | -b -bool bool flag |
| 44 | -r -required (required) |
| 45 | |
| 46 | Commands: |
| 47 | sub subcommand |
| 48 | sub2 another subcommand |
| 49 | ' |
| 50 | |
| 51 | cmd.posix_mode = true |
| 52 | assert cmd.help_message() == r'Usage: command [flags] [commands] |
| 53 | |
| 54 | description |
| 55 | |
| 56 | Flags: |
| 57 | --str str flag |
| 58 | -b --bool bool flag |
| 59 | -r --required (required) |
| 60 | |
| 61 | Commands: |
| 62 | sub subcommand |
| 63 | sub2 another subcommand |
| 64 | ' |
| 65 | } |
| 66 |