Skip to content

Conversation

@dgunzy
Copy link
Contributor

@dgunzy dgunzy commented Dec 4, 2025

Add Rust Clap CLI Code Generation Support

Summary

Adds Rust clap CLI code generation to firestone. Python Click CLI generation remains unchanged except for a bugfix that resolves duplicate argument decorators in update operations.

Changes

New Feature: Rust CLI Generation

  • Added --language flag to generate cli command (defaults to "python" for backward compatibility)
  • New module firestone/spec/cli_rust.py for Rust CLI generation logic
  • New templates cli_module.rs.jinja2 and main.rs.jinja2 for generating idiomatic Rust clap code
  • Complete Rust example in examples/addressbook_rs/ demonstrating CLI + server integration

Bugfix: Duplicate Arguments in Python CLI

  • Fixed duplicate @click.argument decorators in update operations (e.g., address_key, uuid appearing twice)
  • Root cause: Key fields appeared as both path parameters and schema properties
  • Fix: Filter key fields from schema properties in get_resource_attrs() and add deduplication in template

Testing

  • Added Python tests for Rust CLI generation (test/spec/test_cli_rust.py)
  • Updated CI workflows to test Python 3.10-3.13
  • Verified both Python and Rust examples generate and compile cleanly

Backward Compatibility

✅ Fully backward compatible - default language is "python", existing commands work unchanged.

@dgunzy dgunzy force-pushed the rust-cli-gen branch 3 times, most recently from 36d60e5 to a52e67a Compare December 4, 2025 01:51
@ebourgeois
Copy link
Contributor

Interesting @dgunzy ! You seem to be on a roll here, how about we build the crd2openapi, let's talk tomorrow about this, as this woudl be a great path forward for us to support both kube-native and REST, all with one definition!

@ebourgeois
Copy link
Contributor

Can you provide some output of --help and some commands from the generated addressbook here?

@dgunzy
Copy link
Contributor Author

dgunzy commented Dec 4, 2025

Can you provide some output of --help and some commands from the generated addressbook here?

~/OpenSource/firestone/examples/addressbook_rs rust-cli-gen ❯ ./target/release/addressbook_rs --server
Server running on http://0.0.0.0:8080
API documentation available at http://0.0.0.0:8080/openapi.json

CLI

~/OpenSource/firestone/examples/addressbook_rs rust-cli-gen ❯ ./target/release/addressbook_rs --help                                                                16s
This is the CLI and server for the example Addressbook

Usage: addressbook_rs [OPTIONS] [COMMAND]

Commands:
  addressbook   Addressbook operations
  persons       Person operations
  postal-codes  Postal code operations
  help          Print this message or the help of the given subcommand(s)

Options:
      --debug
          Turn on debugging

      --api-key <API_KEY>
          The API key to authorize against API

      --api-url <API_URL>
          The API url, e.g. http://localhost:8080

      --server
          Run the server instead of CLI

      --port <PORT>
          Server port (default: 8080)
          
          [default: 8080]

      --host <HOST>
          Server host (default: 0.0.0.0)
          
          [default: 0.0.0.0]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version
~/OpenSource/firestone/examples/addressbook_rs rust-cli-gen ❯ ./target/release/addressbook_rs addressbook create --help
Create a new address in this addressbook, a new address key will be created

Usage: addressbook_rs addressbook create [OPTIONS] --addrtype <ADDRTYPE> --city <CITY> --country <COUNTRY> --state <STATE> --street <STREET>

Options:
      --address-key <ADDRESS_KEY>  A unique identifier for an addressbook entry
      --addrtype <ADDRTYPE>        The address type, e.g. work or home [possible values: work, home]
      --city <CITY>                The city of this address
      --country <COUNTRY>          The country of this address
      --is-valid                   Address is valid or not
      --people <PEOPLE>            A list of people's names living there
      --person <PERSON>            This is a person object that lives at this address
      --state <STATE>              The state of this address
      --street <STREET>            The street and civic number of this address
  -h, --help                       Print help
~/OpenSource/firestone/examples/addressbook_rs rust-cli-gen ❯ ./target/release/addressbook_rs addressbook create  --addrtype work --city "San Francisco" --country "USA" --state "CA" --street "123 Main St"       
{
  "address_key": "baf70b6a-bfc6-4841-a666-ac40e2e6f962",
  "addrtype": "work",
  "city": "San Francisco",
  "country": "USA",
  "is_valid": false,
  "state": "CA",
  "street": "123 Main St"
}
~/OpenSource/firestone/examples/addressbook_rs rust-cli-gen ❯ ./target/release/addressbook_rs addressbook list 
[
  {
    "address_key": "baf70b6a-bfc6-4841-a666-ac40e2e6f962",
    "addrtype": "work",
    "city": "San Francisco",
    "country": "USA",
    "is_valid": false,
    "state": "CA",
    "street": "123 Main St"
  }
]

@dgunzy
Copy link
Contributor Author

dgunzy commented Dec 4, 2025

Interesting @dgunzy ! You seem to be on a roll here, how about we build the crd2openapi, let's talk tomorrow about this, as this woudl be a great path forward for us to support both kube-native and REST, all with one definition!

Sounds good! Lets chat - and i have some tweaks to make for the generated cli code as well. I can iterate on this for a bit.

Signed-off-by: Daniel Guns <danbguns@gmail.com>
Copy link
Contributor

@ebourgeois ebourgeois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gtg

@dgunzy dgunzy merged commit 298073c into main Dec 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants