diff --git a/codegenerator/rust_cli.py b/codegenerator/rust_cli.py index 13de330..24c714a 100644 --- a/codegenerator/rust_cli.py +++ b/codegenerator/rust_cli.py @@ -1037,6 +1037,7 @@ class RustCliGenerator(BaseGenerator): global_additional_imports.add( f"openstack_sdk::api::{'::'.join(link_res_name.split('/'))}::find as find_{link_res_name.split('/')[-1]}" ) + global_additional_imports.add("eyre::OptionExt") # List of operation variants (based on the body) operation_variants = common.get_operation_variants(spec, args.operation_name) diff --git a/codegenerator/templates/rust_cli/path_parameters.j2 b/codegenerator/templates/rust_cli/path_parameters.j2 index 4e798a5..b8b97bb 100644 --- a/codegenerator/templates/rust_cli/path_parameters.j2 +++ b/codegenerator/templates/rust_cli/path_parameters.j2 @@ -31,6 +31,11 @@ struct {{ res_name | title }}Input { /// {{ res_name | title }} ID. #[arg(long, help_heading = "Path parameters", value_name = "{{ res_name | upper }}_ID")] {{ res_name }}_id: Option<String>, + {%- if res_name == "user" %} + /// Current authenticated user. + #[arg(long, help_heading = "Path parameters", action = clap::ArgAction::SetTrue)] + current_user: bool, + {%- endif %} } {%- endif %} {%- endfor %} diff --git a/codegenerator/templates/rust_macros.j2 b/codegenerator/templates/rust_macros.j2 index 4a439de..4eb86fb 100644 --- a/codegenerator/templates/rust_macros.j2 +++ b/codegenerator/templates/rust_macros.j2 @@ -418,6 +418,18 @@ Some({{ val }}) } }; } + {%- if res_name == "user" and v.remote_name == "user_id" %} + else if self.path.{{ res_name }}.current_{{ res_name }} { + {{ builder }}.{{ v.remote_name }}( + client + .get_auth_info() + .ok_or_eyre("Cannot determine current authentication information")? + .token + .user + .id, + ); + } + {%- endif %} {%- else %} {%- if not v.is_required %} {%- if k != "project_id" %}