-
Notifications
You must be signed in to change notification settings - Fork 217
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
Allow filtering by address state when fetching all addresses #372
Allow filtering by address state when fetching all addresses #372
Conversation
6e84660
to
995a323
Compare
Just (Right a) -> pure $ pure a | ||
Just (Left e) -> do | ||
putErrLn $ T.pack $ getTextDecodingError e | ||
exitFailure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we could print help (the Docopt
) to the console after the failure instead (what getArgOrExitWith
does)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akegalj wrote:
It would be nice if we could print help (the
Docopt
) to the console after the failure instead (whatgetArgOrExitWith
does)
Thanks for this suggestion.
Actually, I can't help wondering if it wouldn't be nicer to print out something even more specific. Instead of printing out the entire help string whenever there's a problem, perhaps we could print out just the specific part that is relevant.
For example:
$ cardano-wallet address list --state on-fire 959b511ffa8213da57443226e3f9e230f956c446
Error: invalid address state: it should be either "used" nor "unused"
Usage: cardano-wallet address list [--port=INT] [--state=STRING] <wallet-id>
See here for a longer discussion: #371
I'm not sure if it's easy to do this with docopt
. (Perhaps switching to optparse-applicative
or some other library would make this easier.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akegalj Given that we can't (currently) print help that is specific to just one command, is it still your preference to print out the whole help string on failure? If so, I can add this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akegalj We currently have this output when a user supplies an invalid value for --state
:
$ cardano-wallet address list --state on-fire 959b511ffa8213da57443226e3f9e230f956c446
Unable to decode address state: it's neither "used" nor "unused"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with the error output in this case.
And in general I am not sure that printing out the whole help as we usually do it atm is a user friendly thing to do. I would rather say "See 'cardano-wallet bla --help' for more details instead if you are interested" because if the whole help is printed then that usually hides the relevant error message.
I have proposed to print out help in this case just so that we can be consistent with the rest of the code - and so that we don't mix multiple styles of error handling in our CLI - and that is on our roadmap so I guess it will be handled soon.
995a323
to
9badd20
Compare
@@ -143,6 +146,15 @@ parseAllArgsWith cli args option = do | |||
getAllArgsOrExit :: Arguments -> Option -> IO (NE.NonEmpty String) | |||
getAllArgsOrExit = getAllArgsOrExitWith cli | |||
|
|||
parseOptionalArg :: FromText a => Arguments -> Option -> IO (Maybe a) | |||
parseOptionalArg args option = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonathanknowles Maybe this would have been useful to use here instead:
https://github.com/input-output-hk/cardano-wallet/blob/master/exe/wallet/Main.hs#L369-L377 ?
An example:
https://github.com/input-output-hk/cardano-wallet/blob/master/exe/wallet/Main.hs#L224
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonathanknowles Maybe this would have been useful to use here instead:
https://github.com/input-output-hk/cardano-wallet/blob/master/exe/wallet/Main.hs#L369-L377 ?
An example:
https://github.com/input-output-hk/cardano-wallet/blob/master/exe/wallet/Main.hs#L224
@KtorZ I'll take a look at this later on to see whether we can use optional
to simplify this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, though the sooner we get rid of docopt the better.
With docopt you need to write two "parsers" for each option. The first is in the help string (written in the docopt external DSL), and the second is where our code gets the argument and applies a parse function to it.
addrs <- liftHandler $ W.listAddresses w wid | ||
return $ coerceAddress <$> addrs | ||
return $ coerceAddress <$> filter filterCondition addrs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not strictly relevant to this PR, but maybe in future we should cache addresses and their status in the database?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rvl How do you envision caching here exactly 🤔 ?
f96e644
to
03841b7
Compare
Rebased on latest master to resolve merge conflict. |
@rvl As soon as we are done with Jormungandr's integration, I think this one will be good to have in the pipeline. |
Issue Number
#356
Overview
I have:
listAddresses
API server function to filter by the optionalstate
query parameter.parseOptionalArg
function to moduleCardano.CLI
.state
filter argument to thecardano-wallet address list
CLI command.Comments