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

How to set a negative value with kdb set #2468

Open
Piankero opened this Issue Mar 8, 2019 · 10 comments

Comments

4 participants
@Piankero
Copy link
Contributor

Piankero commented Mar 8, 2019

How can I set a negative number in kdb?

kdb set '/my/number' '-3'                                                   
#> kdb: invalid option -- '3'
#> Sorry, I could not process the given options (see errors above)
#> 
#> Usage: kdb set <name> [<value>]
#> 
#> Set the value of an individual key.
#> If no value is given, it will be set to a null-value
#> To get an empty value you need to quote like "" (depending on shell)
#> To set a negative value you need to use '--' to stop option processing.
#> (e.g. 'kdb set -- /tests/neg -3')
#> 
#> -H --help                Show the man page.
#> -p --profile <name>      Use a different profile for kdb configuration.
#> -v --verbose             Explain what is happening.
#> -q --quiet               Only print error messages.
#> -V --version             Print version info.
#> -N --namespace <ns>      Specify the namespace to use for cascading keys.
#> -C --color <when>       Print never/auto(default)/always colored output.

" does not help either

@sanssecours

This comment has been minimized.

Copy link
Member

sanssecours commented Mar 8, 2019

I think you should take a closer look at the error message 😊:

#> To set a negative value you need to use '--' to stop option processing.

, which tells you that something like

kdb set /user/tests/negative -- -1
#> Using name user/user/tests/negative
#> Set string to "-1"

should work.

@Piankero

This comment has been minimized.

Copy link
Contributor Author

Piankero commented Mar 8, 2019

Thank you, under this extremely verbose output I did not read that sentence.

@Piankero Piankero closed this Mar 8, 2019

@markus2330 markus2330 added bug and removed question labels Mar 9, 2019

@markus2330

This comment has been minimized.

Copy link
Contributor

markus2330 commented Mar 9, 2019

The text could be improved:

"see errors above" is misleading, "see lines above" might be better?

"If no value is given, it will be set to a null-value" and the following sentence does not have a dot at the end.

@markus2330

This comment has been minimized.

Copy link
Contributor

markus2330 commented Mar 9, 2019

@Piankero what output do you suggest so that you would find the info about --?

@Piankero

This comment has been minimized.

Copy link
Contributor Author

Piankero commented Mar 9, 2019

I am not quite sure if this is possible but if the input was a number, then the text which tells you how to set negative numbers should be arranged at the top. The verbose output of a failed set could only be printed out for every other reason. As I can see there is no number option for kdb set so a solution like this should be fine.

Negative number:

kdb set '/my/number' '-3'                                          
#> kdb: invalid option -- '3'
#> Did you try to set a negative value? Try  'kdb set -- /tests/neg -3'
#> Sorry, I could not process the given options (see reason above)

Anything else:

kdb set '/invalid/option' '-a'                                                   
#> kdb: invalid option -- 'a'
#> Sorry, I could not process the given options (see errors above)
#> 
#> Usage: kdb set <name> [<value>]
#> 
#> Set the value of an individual key.
#> If no value is given, it will be set to a null-value
#> To get an empty value you need to quote like "" (depending on shell)
#> 
#> -H --help                Show the man page.
#> -p --profile <name>      Use a different profile for kdb configuration.
#> -v --verbose             Explain what is happening.
#> -q --quiet               Only print error messages.
#> -V --version             Print version info.
#> -N --namespace <ns>      Specify the namespace to use for cascading keys.
#> -C --color <when>       Print never/auto(default)/always colored output.

The reason for this is that settings will be very likely to have negative numbers. Most likely more often than people setting wrong options (which are more easy to debug than negative numbers)

@markus2330

This comment has been minimized.

Copy link
Contributor

markus2330 commented Mar 9, 2019

Thank you for the proposal!

This would mean that we would need to check for this situation and yield a different error then.

@kodebach is this also easily possible with your command-line parser? I would like to avoid specific code that needs to be thrown after the switch.

@kodebach

This comment has been minimized.

Copy link
Contributor

kodebach commented Mar 10, 2019

Currently we treat everything starting with - as an option. It wouldn't be a huge problem to change this, but AFAIK this is standard POSIX operating procedure. If an option expects an argument and it is given as a separate element of argv (e.g. -o file or --output file) we don't treat leading dashes (-) as options. Also POSIX behaviour AFAIK.

While I don't mind changing behaviour to make user interactions more fluent, I don't like going against POSIX standards to do this.

One thing that would solve this problem is enabling posixly mode for KDB. By enabling this mode, we would stop option processing at the first non option argument (in this case the keyname). Personally I think we should use posixly anyways, for this and various other reasons (e.g. better sub commands).

@markus2330

This comment has been minimized.

Copy link
Contributor

markus2330 commented Mar 11, 2019

Sorry, in my question it was not clear what "this" is. The proposal is to change the error message in the case somebody uses a -<number>, not to allow this.

@kodebach

This comment has been minimized.

Copy link
Contributor

kodebach commented Mar 11, 2019

Changing the error message should be possible as well. It would require modifications, but we could just set some metadata on the parent key, whenever an error is caused by an element of argv.

@markus2330

This comment has been minimized.

Copy link
Contributor

markus2330 commented Mar 11, 2019

Then let us improve the error message for this case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.