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

Introduce formatter and output mechanism #3

Open
krisnova opened this issue Dec 30, 2022 · 6 comments
Open

Introduce formatter and output mechanism #3

krisnova opened this issue Dec 30, 2022 · 6 comments
Labels
Good First Issue Great for newcomers to the project! Let someone know in Discord if you pick one up.

Comments

@krisnova
Copy link
Contributor

krisnova commented Dec 30, 2022

We need a clean way to output and query the output of the program.

Ideally we will be able to do something like the following:

ae get pods --json # Spits out something we can pipe to jq
ae get pods --yamo # Spits out something we can pipe to yq
ae get pods --go # Spits out syntactically correct Go structs we can copy/paste
ae get pods --table # Spits out a table in stdout that is auto formatted to the terminal
@krisnova krisnova added the Good First Issue Great for newcomers to the project! Let someone know in Discord if you pick one up. label Dec 30, 2022
@krisnova krisnova changed the title Introduce a logger Introduce formatter and output mechanism Dec 30, 2022
@krisnova
Copy link
Contributor Author

Note: we do not want a logger like Logrus as we want to be able to query the data that ae returns natively on the command line

@keltia
Copy link

keltia commented Dec 30, 2022

As told on stream, github.com/intel/tfortools is a great table formatter. (@Corwyn666)

@daegalus
Copy link
Contributor

For pretty outputs over interop outputs, I recommend Charm libs. https://charm.sh/ specifically Bubble Tea and Lip Gloss

@RRethy
Copy link
Contributor

RRethy commented Jan 5, 2023

I've started looking at this, I should have time on the weekend to put my changes in a PR.

@voigt
Copy link
Collaborator

voigt commented Jan 8, 2023

Thought about this one a bit now and have a couple of thoughts I'd like to share/discuss:

  • Where is --go as a requirement coming from? I don't quite understand what scenarios this might be useful. Is it worth the effort? Any examples of apps that have this?
  • What exactly do we mean by "table"? Like a list of tabbed values or do we insist on decorators like borders etc.?
  • Are there additional requirements to a table output like kubectls --format option?
  • Can we guarantee 2D objects that we want to print?

I was looking into the implementation of kubectl, which seems to use https://github.com/liggitt/tabwriter. I guess we could reuse quite a bit of its implementation if we'd follow a similar approach: link.

  • Skimming this code I thought about another output format that I like using kubectl: -o jsonath='{...}' - may be another thing we would like to support?

@keltia mentioned github.com/intel/tfortools, which sounds like a nice option, but is already archived. Not sure if we should rely on it, as it is not maintained anymore.

@RRethy
Copy link
Contributor

RRethy commented Jan 9, 2023

Where is --go as a requirement coming from? I don't quite understand what scenarios this might be useful. Is it worth the effort? Any examples of apps that have this?

I'm curious about this too. Would it print a struct definition, a instance of a struct, or client-go grpc code to use the struct? I can say it would've been cool (and useful) if kubectl would print out valid client-go code based on the get command I ran so I'd open to trying that out (after we get our grpc client merged).

What exactly do we mean by "table"? Like a list of tabbed values or do we insist on decorators like borders etc.?

I was thinking something like kubectl -owide.

Can we guarantee 2D objects that we want to print?

I wouldn't think so, I'd expect it to depend on the subcommand. That's one of the reasons in my PR above the printers are configured by the subcommand.

@keltia mentioned github.com/intel/tfortools, which sounds like a nice option, but is already archived. Not sure if we should rely on it, as it is not maintained anymore.

I looked at that too, I agree with what you said about jsonpath as an alternative, or we could also just rely on -o json and let users pipe the output into jq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Great for newcomers to the project! Let someone know in Discord if you pick one up.
Projects
None yet
Development

No branches or pull requests

5 participants