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

cli: accept xdr via an argument and not only as a file or stdin #406

Open
leighmcculloch opened this issue Jan 13, 2025 · 2 comments
Open

Comments

@leighmcculloch
Copy link
Member

leighmcculloch commented Jan 13, 2025

The stellar-xdr cli (which is also the stellar xdr command in the stellar-cli) accepts as input xdr either via file or stdin.

e.g. via file:

stellar xdr decode myfile.xdr myfile2.xdr

e.g. via stdin:

cat myfile.xdr | stellar xdr decode
echo ... | stellar xdr decode

It's been reported that it would be convenient if the command provided a way to pass the xdr as an argument as well.

When the command was first implemented passing the xdr as an argument was omitted because in bash-like environments you get that functionality for free.

e.g.

stellar xdr decode <(echo ...)

However, the stellar-cli is supported across a variety of environments, including Windows, where bash may not be in use. For the sake of making the cli consistently usable on all environments, which simplifies tutorials and teaching material (e.g. conference slides), we could add the ability to pass the xdr as an argument.

We should only do this if it doesn't make the rest of the UX more complex, and only if this is high impact enough.

cc @stellar/devx @tomerweller

@leighmcculloch
Copy link
Member Author

leighmcculloch commented Jan 13, 2025

The first thought I had is this:

# existing behaviour preserved
stellar xdr decode myfile.xdr myfile2.xdr # assumes file because files passed
cat myfile.xdr | stellar xdr decode # assumes stdin because no files given
echo ... | stellar xdr decode # assumes stdin because no files given

# new behavior added
stellar xdr decode --read files myfile.xdr myfile2.xdr # no assumption because parameter specified
cat myfile.xdr | stellar xdr decode --read stdin # no assumption because parameter specified
echo ... | stellar xdr decode --read stdin # assumes stdin because no files given
stellar xdr decode --read args AAAAAAjBALVT2rv9LPtsuKN2lrdTALY5naljcz5sujEVXHX6

But that's quite complex. Easy enough to read, but difficult to discover.

@leighmcculloch
Copy link
Member Author

Another thought I had is this:

# existing behaviour preserved
stellar xdr decode myfile.xdr myfile2.xdr # assumes file because files passed
cat myfile.xdr | stellar xdr decode # assumes stdin because no files given
echo ... | stellar xdr decode # assumes stdin because no files given

# new behavior added
stellar xdr decode AAAAAAjBALVT2rv9LPtsuKN2lrdTALY5naljcz5sujEVXHX6

Where the command guesses if the input is XDR or a file by both trying to decode the input, as well as checking if a file exists by that name.

This is probably the best user experience, although I don't love the unpredictable behavior. But it is probably the best UX. In situations where the input is valid XDR and a file present on disk, it may be wise to output a warning to stderr about which is being used.

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

No branches or pull requests

1 participant