Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic command options #5

Closed
azmeuk opened this issue Aug 26, 2024 · 7 comments · Fixed by #7
Closed

Dynamic command options #5

azmeuk opened this issue Aug 26, 2024 · 7 comments · Fixed by #7
Labels
enhancement New feature or request

Comments

@azmeuk
Copy link
Contributor

azmeuk commented Aug 26, 2024

For the sake of usage convenience, scim2-cli should provide custom commands for every models, for example on create and replace command:

scim create user --user-name foo --name.formatted-name bar

There will be difficulties to build a simple API for multiple complex attributes, for instance I am not sure if click allows this usage:

scim create user --user-name foo --email.0.value [email protected] --email.0.primary true --email.1.value [email protected]

At least for a start we can offer this API:

scim create user --user-name foo --email "[email protected],primary=true" --email "[email protected]"
@azmeuk azmeuk added the enhancement New feature or request label Aug 26, 2024
@sblondon
Copy link

In the last example, value is not filled for [email protected]. With value key added, it would be:

scim create user --user-name foo --email "[email protected],primary=true" --email "value [email protected]"

I wonder if there is a risk to be ambiguous without forcing key:value data.

I ignore your usecase but using a file could be another way to explore:

scim create user < user_definition

with user_definition content:

[email protected]
email.0.primary=true
email.1.value [email protected]

@azmeuk
Copy link
Contributor Author

azmeuk commented Aug 27, 2024

I wonder if there is a risk to be ambiguous without forcing key:value data.

Yep, that was a typo. I meant key=value.

I ignore your usecase but using a file could be another way to explore:

Currently scim2-cli uses the standard input, but expects JSON:

$ scim2 create user << EOL
{
    "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
    "userName": "[email protected]"
}

I think JSON is still relevant for advanced payloads, but the --key=value format can be useful to handle simple requests.

@azmeuk
Copy link
Contributor Author

azmeuk commented Sep 1, 2024

The dot separator for sub-attributes might be hard to use because of pallets/click#2768, I think we will go with -- instead.

scim create user --user-name foo --name--formatted-name bar

@sblondon
Copy link

sblondon commented Sep 2, 2024

From a user point of view, there are plenty hyphens to parse when writing the command line: -- as sub attributes separator, - in name attributes, and -- for long parameters (the most obvious ones). Perhaps it could be another character like ::

scim create user --user-name foo --name:formatted-name bar

: is not a valid character in name attributes (RFC 7643, section 2.1) whereas - is a valid character. I thought of : character due to schemas string but another separator could match too the need (until it's not alphanumumeric, hyphen, underscore or dollar characters).

Note that I did not check how click manages : character.

@azmeuk
Copy link
Contributor Author

azmeuk commented Sep 4, 2024

I like the : separator!
However there is still an issue on the click side: this method parses the decls i.e. the parameter names. Lines 2590 and 2591, the decl name is expected to be a python identifier because it is then passed as an argument for a callback method.

>>> "name:formatted_name".isidentifier()
False

I am not sure about why click has this limitation, since non-identifiers decls are still usable (although less convenient):

>>> def foobar(**kwargs):
...     print(kwargs["name:formatted_name"])
>>> foobar(**{"name:formatted_name": "George Abitbol"})
George Abitbol

Related discussion on click bugtracker.

@azmeuk
Copy link
Contributor Author

azmeuk commented Sep 6, 2024

pydanclick is a good lead for externalizing the command management but I encountered some issues that makes it not fitted at the moment.

@azmeuk
Copy link
Contributor Author

azmeuk commented Sep 7, 2024

The cleanest syntax I can think of is probably:

scim create user --user-name "foobar" \
    --emails --emails-value "[email protected]" --primary "true" \
    --emails --emails-value "[email protected]"

Here --emails would just mark the creation of a new Email object, filled by the following --emails-* parameters, until a new --emails is met.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants