github.com/go-swagger/go-swagger@v0.31.0/docs/generate/cli.md (about)

     1  ---
     2  title: Generate a CLI client
     3  date: 2023-01-01T01:01:01-08:00
     4  draft: true
     5  weight: 25
     6  ---
     7  # Generate a CLI (command line tool) from swagger spec
     8  This toolkit can generate a CLI to interact with your server
     9  
    10  ### Features of generated app
    11  * auto-completion for bash, zsh, fish and powershell.
    12  * use config file to specify common flags.
    13  * each param and each field in body has a cli flag. etc.
    14  
    15  ### CLI usage
    16  ```
    17  Usage:
    18    swagger [OPTIONS] generate cli [cli-OPTIONS]
    19  
    20  generate a command line client tool from the swagger spec
    21  
    22  Application Options:
    23    -q, --quiet                                                                     silence logs
    24        --log-output=LOG-FILE                                                       redirect logs to file
    25  
    26  Help Options:
    27    -h, --help                                                                      Show this help message
    28  
    29  [cli command options]
    30        -c, --client-package=                                                       the package to save the client specific code (default: client)
    31        -P, --principal=                                                            the model to use for the security principal
    32            --default-scheme=                                                       the default scheme for this API (default: http)
    33            --principal-is-interface                                                the security principal provided is an interface, not a struct
    34            --default-produces=                                                     the default mime type that API operations produce (default:
    35                                                                                    application/json)
    36            --default-consumes=                                                     the default mime type that API operations consume (default:
    37                                                                                    application/json)
    38            --skip-models                                                           no models will be generated when this flag is specified
    39            --skip-operations                                                       no operations will be generated when this flag is specified
    40        -A, --name=                                                                 the name of the application, defaults to a mangled value of info.title
    41            --cli-app-name=                                                         the app name for the cli executable. useful for go install. (default:
    42                                                                                    cli)
    43  
    44      Options common to all code generation commands:
    45        -f, --spec=                                                                 the spec file to use (default swagger.{json,yml,yaml})
    46        -t, --target=                                                               the base directory for generating the files (default: ./)
    47            --template=[stratoscale]                                                load contributed templates
    48        -T, --template-dir=                                                         alternative template override directory
    49        -C, --config-file=                                                          configuration file to use for overriding template options
    50        -r, --copyright-file=                                                       copyright file used to add copyright header
    51            --additional-initialism=                                                consecutive capitals that should be considered intialisms
    52            --allow-template-override                                               allows overriding protected templates
    53            --skip-validation                                                       skips validation of spec prior to generation
    54            --dump-data                                                             when present dumps the json for the template generator instead of
    55                                                                                    generating files
    56            --strict-responders                                                     Use strict type for the handler return value
    57            --with-expand                                                           expands all $ref's in spec prior to generation (shorthand to
    58                                                                                    --with-flatten=expand)
    59            --with-flatten=[minimal|full|expand|verbose|noverbose|remove-unused]    flattens all $ref's in spec prior to generation (default: minimal,
    60                                                                                    verbose)
    61  
    62      Options for model generation:
    63        -m, --model-package=                                                        the package to save the models (default: models)
    64        -M, --model=                                                                specify a model to include in generation, repeat for multiple
    65                                                                                    (defaults to all)
    66            --existing-models=                                                      use pre-generated models e.g. github.com/foobar/model
    67            --strict-additional-properties                                          disallow extra properties when additionalProperties is set to false
    68            --keep-spec-order                                                       keep schema properties order identical to spec file
    69            --struct-tags=                                                          the struct tags to generate, repeat for multiple (defaults to json)
    70  
    71      Options for operation generation:
    72        -O, --operation=                                                            specify an operation to include, repeat for multiple (defaults to all)
    73            --tags=                                                                 the tags to include, if not specified defaults to all
    74        -a, --api-package=                                                          the package to save the operations (default: operations)
    75            --with-enum-ci                                                          allow case-insensitive enumerations
    76            --skip-tag-packages                                                     skips the generation of tag-based operation packages, resulting in a
    77                                                                                    flat generation
    78  ```
    79  
    80  ### Build a CLI
    81  There is an example cli and tutorial provided at: https://github.com/go-swagger/go-swagger/tree/master/examples/cli
    82  
    83  To generate a CLI:
    84  ```
    85  swagger generate cli -f [http-url|filepath] --cli-app-name [app-name]
    86  ```
    87  Cli is a wrapper of generated client code (see [client](./client.md) for details), so all client generation options are honored.
    88  
    89  To build the generated CLI code:
    90  ```
    91  go build cmd/<app-name>/main.go 
    92  ```
    93  Or install in your go/bin
    94  ```
    95  go install cmd/<app-name>/main.go
    96  ```
    97  
    98  See details of the generated app help message for usage
    99  ```
   100  <app name> help
   101  ```
   102  
   103  A more detailed/complicated example is generated CLI for docker engine: https://github.com/go-swagger/dockerctl