Giter Site home page Giter Site logo

pretty's Introduction

Pretty

View files prettified on CLI

Development

Install as binary:

$ cargo install --path .
$ pretty --help
Usage: pretty [OPTIONS] <FILE>

Arguments:
  <FILE>

Options:
  -f, --flatten <FIELDS>           Comma seperated list of fields to flatten
  -c, --color <COLOR>              [default: never] [possible values: never, always, auto]
  -s, --select <SELECT>            [default: .]
      --select-mode <SELECT_MODE>  [default: auto] [possible values: only, append, auto]
      --sort <FIELD>               Field to sort by
      --filter <FIELD=VALUE>       Filter expression
  -h, --help                       Print help information
  -V, --version                    Print version information

Run samples:

$ pretty samples/test2.json

┌─────────────────┬───────┬──────────────┬──────┬───────┐
│name             │age    │secretIdentity│powers│address│
├─────────────────┼───────┼──────────────┼──────┼───────┤
│"Molecule Man"   │29     │"Dan Jukes"   │[..]  │{..}   │
├─────────────────┼───────┼──────────────┼──────┼───────┤
│"Madame Uppercut"│39     │"Jane Wilson" │[..]  │{..}   │
├─────────────────┼───────┼──────────────┼──────┼───────┤
│"Eternal Flame"  │1000000│"Unknown"     │[..]  │       │
└─────────────────┴───────┴──────────────┴──────┴───────┘

$ pretty samples/test2.json --flatten=address

┌─────────────────┬───────┬──────────────┬──────┬───────────────┬──────────────┬──────────────┐
│name             │age    │secretIdentity│powers│address.country│address.planet│address.galaxy│
├─────────────────┼───────┼──────────────┼──────┼───────────────┼──────────────┼──────────────┤
│"Molecule Man"   │29     │"Dan Jukes"   │[..]  │"US""Earth"       │              │
├─────────────────┼───────┼──────────────┼──────┼───────────────┼──────────────┼──────────────┤
│"Madame Uppercut"│39     │"Jane Wilson" │[..]  │               │"PL120""Andromeda"   │
├─────────────────┼───────┼──────────────┼──────┼───────────────┼──────────────┼──────────────┤
│"Eternal Flame"  │1000000│"Unknown"     │[..]  │               │              │              │
└─────────────────┴───────┴──────────────┴──────┴───────────────┴──────────────┴──────────────┘

$ pretty samples/test2.json --select 'powers.[].0' --select-mode append

┌─────────────────┬───────┬──────────────┬──────┬───────┬──────────────────────┐
│name             │age    │secretIdentity│powers│address│powers.[].0           │
├─────────────────┼───────┼──────────────┼──────┼───────┼──────────────────────┤
│"Molecule Man"   │29     │"Dan Jukes"   │[..]  │{..}   │"Radiation resistance"│
├─────────────────┼───────┼──────────────┼──────┼───────┼──────────────────────┤
│"Madame Uppercut"│null   │"Jane Wilson" │[..]  │{..}   │"Million tonne punch" │
├─────────────────┼───────┼──────────────┼──────┼───────┼──────────────────────┤
│"Eternal Flame"  │1000000│"Unknown"     │[..]  │       │"Immortality"         │
└─────────────────┴───────┴──────────────┴──────┴───────┴──────────────────────┘

$ pretty samples/test2.json --sort age

┌─────────────────┬───────┬──────────────┬──────┬───────┐
│name             │age    │secretIdentity│powers│address│
├─────────────────┼───────┼──────────────┼──────┼───────┤
│"Molecule Man"   │29     │"Dan Jukes"   │[..]  │{..}   │
├─────────────────┼───────┼──────────────┼──────┼───────┤
│"Eternal Flame"  │1000000│"Unknown"     │[..]  │       │
├─────────────────┼───────┼──────────────┼──────┼───────┤
│"Madame Uppercut"│null   │"Jane Wilson" │[..]  │{..}   │
└─────────────────┴───────┴──────────────┴──────┴───────┘

# Filter only supports equals for now
$ pretty samples/test2.json --filter 'age=29'

┌──────────────┬───┬──────────────┬──────┬───────┐
│name          │age│secretIdentity│powers│address│
├──────────────┼───┼──────────────┼──────┼───────┤
│"Molecule Man"│29 │"Dan Jukes"   │[..]  │{..}   │
└──────────────┴───┴──────────────┴──────┴───────┘

Enabling color

Use --color auto or --color always to enable color.

$  pretty samples/test2.json --color auto

Colored Ouput

pretty's People

Contributors

kanatti avatar

Stargazers

 avatar

Watchers

 avatar

pretty's Issues

Revise API for different commands

For non-interactive mode, revise API for different commands like sort, filter, select, flatten etc.

  • Should it be chain one after another?
  • Or all commands as arguments?
  • Should we limit non-interactive mode to fewer commands? than interactive

Command to show inferred schema

Outputs

  • full fledged schema json
  • user friend rendered string on terminal

Open questions

  • How to infer and what all to infer?

We can start with basic and improve (like enumarations etc)

Clip large values

  • Clip columns
  • Clips rows
  • Clips string values

Also take into consideration available width and height of terminal?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.