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

Usability of the NEAR CLI in scripting? #437

Open
artob opened this issue Jan 18, 2025 · 6 comments
Open

Usability of the NEAR CLI in scripting? #437

artob opened this issue Jan 18, 2025 · 6 comments
Assignees

Comments

@artob
Copy link
Contributor

artob commented Jan 18, 2025

❓ What is the plan to make the CLI usable for scripting? Because as it stands currently, that seems rather difficult:

Invoking: near account view-account-summary near network-config testnet now

Image

Invoking: near account view-account-summary notfound network-config testnet now

Image

The specific difficulties encountered here are:

  1. The output structure (on stdout) is extremely verbose, clearly meant for humans only, and unstable over time
  2. There is spurious extra output being emitted (onto stderr), and there appear to be no CLI options to disable:
    • The "Here is your console command if you need to script it or re-run" tutorial output
    • The "Receiving an inquiry about your account" progress output
  3. There appears to be no CLI option (such as --quiet or --silent) for silencing all spurious output
  4. There appears to be no CLI option (such as --output json) for printing machine-readable output
  5. The error output (all on stderr) has intermixed into it progress output and tutorial output, and is also overly verbose
  6. The exit status in case of any error is an undifferentiated exit code 1, instead of something useful such as sysexits(3) exit codes
@github-project-automation github-project-automation bot moved this to NEW❗ in DevTools Jan 18, 2025
@artob artob changed the title Usage of the NEAR CLI in scripting? Usability of the NEAR CLI in scripting? Jan 18, 2025
@frol
Copy link
Collaborator

frol commented Jan 20, 2025

@artob What is your use case? Wouldn't it be easier to use near-api-rs, py-near, or near-api-js instead of shelling out CLI commands?

@artob
Copy link
Contributor Author

artob commented Jan 20, 2025

@frol The category of use cases is shell scripting, which is the single largest and most significant category for any CLI tool.

The novel, explicit command structure of near-cli-rs is in principle uniquely well suited to scripting, as compared to most CLI tools including the old JS-based CLI. In fact, arguably near-cli-rs would be even better suited to scripting than to actual use by humans, since for the latter it tends to be rather verbose which goes against the grain for the supermajority of CLI utilities in wide use. However, near-cli-rs's inherent high potential for scripting is right now being held back by the incidental issues identified above.

Suggest it would be a good idea to take a clear decision on whether scripting is supported or not. If not, consider removing "to script it" from the following output printed on every invocation:

Here is your console command if you need to script it or re-run:

@frol
Copy link
Collaborator

frol commented Jan 21, 2025

@artob Thank you for surfacing your experience! I think --quiet and --output json are good suggestions that we can implement relatively easy. Exit codes are harder since that will require to design those first and then implement custom errors to distinguish them.

Just FYI, I also use NEAR CLI for scripting, but I use the scripts interactively - so I setup aliases and finish the command in interactive mode, so I rely on human output.

@artob
Copy link
Contributor Author

artob commented Jan 21, 2025

@artob Thank you for surfacing your experience! I think --quiet and --output json are good suggestions that we can implement relatively easy. Exit codes are harder since that will require to design those first and then implement custom errors to distinguish them.

For exit codes, suggest adopting the sysexits(3) standard codes. They are granular enough to be useful discriminators, without requiring tons of work. There isn't really any other comparable set of standard codes.

For a Rust implementation, see e.g. github.com/dryrust/clientele.rs/blob/master/lib/clientele/src/sysexits.rs.

@FroVolod FroVolod self-assigned this Jan 25, 2025
artob added a commit to asimov-protocol/near-cli-rs that referenced this issue Jan 27, 2025
artob added a commit to asimov-protocol/near-cli-rs that referenced this issue Jan 27, 2025
frol pushed a commit that referenced this issue Jan 27, 2025
artob added a commit to dryruby/near.rb that referenced this issue Jan 28, 2025
@gagdiez
Copy link
Contributor

gagdiez commented Jan 28, 2025

I just came to the issues to open a similar one! happy to find yours @artob

@FroVolod would be amazing to have a --silent option, in my case because I get lost in the output! It is simply too verbose right now

@gagdiez
Copy link
Contributor

gagdiez commented Jan 28, 2025

For example here I am making the exact same action on near-cli-js and near-cli-rs, and the output of near-cli-rs does not fit into my screen

Image

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

No branches or pull requests

4 participants