๐Ÿšƒ lib for CLI utilities, printing, and error handling

Overview

axocli

crates.io docs Rust CI

Common code for setting up a CLI App and handling errors/printing.

Example

See examples/axoapp.rs for a walkthrough/example.

Some various interesting example invocations to play with:

# clap help
cargo run --example axoapp -- --help

# success
cargo run --example axoapp -- 5
cargo run --example axoapp -- 5 --output-format=json

# normal error
cargo run --example axoapp -- 2
cargo run --example axoapp -- 2 --output-format=json

# panic (setting RUST_BACKTRACE=1 here is also interesting)
cargo run --example axoapp -- 0
cargo run --example axoapp -- 0 --output-format=json

# clap error
cargo run --example axoapp --

What Does It Do?

First off, it handles setting up:

  • a tracing subscriber (currently the kind that cargo-dist uses, more work needed for oranda's use)
  • a miette formatter (so we can have a shared Look And Feel)
  • a panic handler (to get more control over output if the app panics)
  • (not implemented but likely in the future) a tokio runtime

It also handles printing top-level errors, notably including a json_errors mode where the error gets formatted to json and printed to stdout, while still printing a human-friendly version to stderr. This is done for both an error returned from real_main and panics. So anything expecting machine-readable output from our apps will not freak out and get something unparseable when things error/panic. It will also set the process exit code on error (with std::process::exit, on the assumption that all cleanup was done when we returned/panicked out of real_main).

It also exposes the json diagnostic formatting machinery so you can Write them wherever or turn them into serde_json::Values. This is useful for returning a larger result with diagnostics nested inside of it (say, for reporting warnings).

License

Licensed under either of

at your option.

You might also like...
Rust lib for fetching official protoc (Protocol Buffer compiler) releases

protoc-fetcher Rust library for fetching official Protocol Buffer compiler (protoc) releases, pegged to a specific version. protoc-fetcher downloads a

Uma lib para a API do Brasil API (para o Rust)
Uma lib para a API do Brasil API (para o Rust)

Uma lib para a API do BrasilAPI (para o Rust) Features CEP (Zip code) DDD Bank CNPJ IBGE Feriados Nacionais Tabela FIPE ISBN Registros de domรญnios br

Simple time handling in Rust

time Documentation: latest release main branch book Minimum Rust version policy The time crate is guaranteed to compile with any release of rustc from

A simple endian-handling library for Rust

endi Yet another endian handling library for Rust. The approach is very similar to that of byteordered crate with its Endianness enum, except that end

A cli tool to write your idea in terminal
A cli tool to write your idea in terminal

Ideas ideas is a cli tools to write your idea in your terminal. Demo Features tagged idea, contains tips, idea, todo status switch ascii icon write yo

clone of grep cli written in Rust. From Chapter 12 of the Rust Programming Language book

minigrep is a clone of the grep cli in rust Minigrep will find a query string in a file. To test it out, clone the project and run cargo run body poem

CLI program written in Rust to anonymize DICOM files

dicom-anonymizer CLI program written in Rust to anonymize DICOM files anonymizer 0.1.0 Domenic Melcher USAGE: anonymizer [OPTIONS] FILE ARGS:

Rust app that creates cli quiz for you!

quizer rust app that creates cli quiz for you! Installation Download binary release or build from source using cargo Make binary executable chmod +x /

Simple CLI tool to create dummy accounts with referral links to give yourself free Plus.
Simple CLI tool to create dummy accounts with referral links to give yourself free Plus.

Free Duolingo Plus A simple CLI tool to create dummy accounts with referral links to give yourself free Plus (max 24/41 weeks depending on whether you

Comments
  • testing mode

    testing mode

    Right now I don't think the the design is well-suited for tests.

    For global init in tests it's typical to have a global lazy_static that all tests try to use, ensuring global setup happens once. However we currently make setup and running a single transactional operation. Ideally we could have an alternate way of starting things that lets each test share global init that can be shared AND let each have their own "sandbox". Like it would be great if you could ask for logs that were generated by test1 without test2 messing with it.

    idk how much of a pipe dream the full sandboxing stuff is, but at very least we want to be able to get the primary output/error of each test individually.

    enhancement 
    opened by Gankra 0
  • tokio runtime setup

    tokio runtime setup

    oranda wants this, and i'm sure we'll have other apps that use tokio that want to share the logic

    The entered runtime could be passed as part of CliApp, this was factored into the design.

    enhancement 
    opened by Gankra 0
  • log files

    log files

    oranda needs this

    orogene has a super complicated/robust solution:

    https://github.com/orogene/orogene/blob/main/src/lib.rs#L145-L255 and https://github.com/orogene/orogene/blob/main/src/lib.rs#L295-L306 set up logging, and also automatically always logging to a log file in the cache, then if there's an error, it says "here's where the log file is, if you want it. It also keeps the most recent 5 logs for you in case you wanna go back and see.

    oh and it also has all the stuff you need so you can provide the really fancy EnvFilter strings to --loglevel, instead of just warn/info/etc (--loglevel node_maintainer=trace,warn)

    enhancement 
    opened by Gankra 0
  • prettier backtraces

    prettier backtraces

    We do some custom backtrace stuff in our panic hook (the relevant details being in panic.rs) and I don't really like the current output. It's very noisy, especially with printing the address of a frame even if we symbolicated it. That said I need to test it out in "production" environments where symbols are worse (no local debuginfo sitting in target/) to figure out what can be trimmed or not.

    The situation isn't 1:1 (not using the backtrace crate) but minidump_processor has much prettier output with this more complex impl: https://github.com/rust-minidump/rust-minidump/blob/main/minidump-processor/src/process_state.rs#L737

    enhancement 
    opened by Gankra 0
Releases(v0.1.0)
Owner
axo
axo
Simple, automatic, and customizable tree pretty-printing in Rust.

display_tree Simple, automatic, and customizable tree pretty-printing in Rust. This crate provides tools to easily pretty-print data as a tree, includ

Cameron Delong 20 Dec 24, 2022
๐Ÿš€simple server that returns error codes with their respective messages and debug information, written in rust ๐Ÿฆ€

ErrorServer ?? A simple & lightweight server that returns a HTML page of the error code with its respective message and debug information, written in

Jakob 2 Dec 15, 2022
Grimsby is an Erlang Port written in Rust that can close its standard input while retaining standard output (and error)

Grimsby An Erlang Port provides the basic mechanism for communication from Erlang with the external world. From the Ports and Port Drivers: Erlang Ref

Peter Morgan 5 May 29, 2023
A typesafe, flexible, simple, and user-friendly unit system library for Rust that has good error messages.

uy A typesafe, flexible, simple, and user-friendly unit system library for Rust that has good error messages. Usage uy not only stores the unit of a v

Lachlan Sneff 19 Aug 8, 2023
Powerful math lib for Vector, Matrix and Quaternion operations

An opinionated, powerful math lib for Vector2, Vector3, Matrix and Quaternion operations Vector2 Add, Sub, Div, Mul, Eq Distance Move towards target a

O(ส’) 4 Mar 28, 2022
Powerful math lib for Vector, Matrix and Quaternion operations

An opinionated, powerful math lib for Vector2, Vector3, Matrix and Quaternion operations Vector2 Add, Sub, Div, Mul, Eq Distance Move towards target a

O(ส’) 4 Mar 28, 2022
A tiny Rust std-lib for Linux x86_64 and aarch64

Tiny std Like a bad, probably buggy, tiny standard library for Linux. When it's appropriate If you are actually trying to do something solid, checkout

null 4 Dec 17, 2022
A bit-packed k-mer representation (and relevant utilities) for rust

K-mer class for rust The purpose of this repository is to build a simple library that exposes a bit-packed k-mer class for use in rust-based bioinform

COMBINE lab 41 Dec 15, 2022
๐Ÿ“˜ Utilities for the Fibonacci Number and Sequence

Fibora Port of fibonacci-deno for Rust. Utilities for the Fibonacci Number and Sequence. Usage This package exposes two Functions, fibonacci and fibon

Eliaz Bobadilla 5 Apr 6, 2022
Utilities for converting Vega-Lite specs from the command line and Python

VlConvert VlConvert provides a Rust library, CLI utility, and Python library for converting Vega-Lite chart specifications into static images (SVG or

Vega 24 Feb 13, 2023