Skip to content

--flag and --environment are swapped on expiring-targets and flag-triggers commands (path params filled by position) #1067

Backlog

Description

@littlewoo-legora

Describe the bug

On 12 generated commands, ldcli sends the value of one path flag in the position of another. For example, ldcli flags update-expiring-targets --flag F --environment E requests /api/v2/flags/{project}/E/expiring-targets/F, with the environment key in the flag position and the flag key in the environment position.

buildURLWithParams (cmd/resources/resources.go) replaces every {…} in the path template with %s and fills them in the order of the command's Params list. makeRequest builds that list from op.Params and ignores each parameter's name. For these commands the generated Params order is project, environment, flag (or segment). Their paths put the flag (or segment) before the environment:

/api/v2/flags/{projectKey}/{featureFlagKey}/expiring-targets/{environmentKey}

Affected commands, from cmd/resources/resource_cmds.go on main:

Command Path
flags list-expiring-context-targets /api/v2/flags/{projectKey}/{featureFlagKey}/expiring-targets/{environmentKey}
flags update-expiring-targets same
flags list-expiring-user-targets /api/v2/flags/{projectKey}/{featureFlagKey}/expiring-user-targets/{environmentKey}
flags update-expiring-user-targets same
segments list-expiring-targets /api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}
segments update-expiring-targets same
segments list-expiring-user-targets /api/v2/segments/{projectKey}/{segmentKey}/expiring-user-targets/{environmentKey}
segments update-expiring-user-targets same
flag-triggers create /api/v2/flags/{projectKey}/{featureFlagKey}/triggers/{environmentKey}
flag-triggers list same
flag-triggers update /api/v2/flags/{projectKey}/{featureFlagKey}/triggers/{environmentKey}/{id}
flag-triggers delete same

To reproduce

With a project my-project, a flag my-flag and an environment production:

ldcli flags list-expiring-context-targets --project my-project --flag my-flag --environment production

Result:

{"code":"not_found","message":"Unknown environment key my-flag","statusCode":404}

With the two values swapped, the request reaches the intended endpoint:

ldcli flags list-expiring-context-targets --project my-project --flag production --environment my-flag
# {"items":[], ...}

update-expiring-targets behaves the same way. With an empty instruction list, which the API rejects without changing anything, the documented order returns 404 Unknown environment key my-flag. The swapped order returns 400 no instructions provided.

Expected behavior

Each path parameter is substituted by name, so --flag fills {featureFlagKey} and --environment fills {environmentKey} whatever order the parameters are declared in.

A fix in buildURLWithParams: replace each {name} with the value of the parameter whose camel-cased name matches it, ignoring the case of ID/Id. A fix in the generator: emit Params in path order.

CLI version

3.16.0. The code is the same on main as of 2 Dec 2026.

OS/platform

macOS, Homebrew install.

Additional context

flags update and the other commands whose Params order matches the path are not affected. Nine further commands differ from their path only in the case of ID (trigger-id against {triggerID}, for example) and substitute correctly today. A by-name fix would need to match them case-insensitively.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions