Open dantswain opened 7 years ago
I'm going to make this ticket a bit bigger. Let's pipe the data yielded by each skill and into a formatting skill. This means that every existing "source" skill must yield a JSON object so that it may be consumed by a formatter. By default, all JSON output from those sources will be passed to the Format-JSON
skill that pretty prints the JSON data in pre-formatted text. This formatter may be invoked explicitly using unix pipe syntax; List-Skills | Format-JSON
is equivalent to List-Skills
. The other formatter we must have is formatting as a table (Format-Table
). I think table formatting can be sufficiently large so I'll make another ticket for that.
Note, novelties like "I am error" can be exempted.
Generally, if parsing as a JSON object fails, just print out the data as a string.
I'm not sure I like this... it seems like overkill for some commands. What is the use case for doing !list-skills
or !list-minions
and getting a JSON output? It would have to take something in native format, convert it to JSON, then only pretty print it if you ask for it to be pretty printed? I would kind of expect !list-minions
to just print a column of text. How does one format the output of ls -lah /tmp
to JSON, and what value does that add?
I think this could be a useful feature for some commands that would naturally spit out things like JSON, to have it pretty-print the output. It seems like something that would work more naturally as an opt-in. It could be implemented something like Protocol (called interfaces in golang and some other languages) - you could define your command and then somehow specify what kind of data it outputs, which we would pick up and present as options for formatting.
One thing that I do think would be really nice is some control over how the output is posted to slack - as plain text, as backtick-quoted text, as a fenced code block, as a snippet (optionally specifying the language, say, json), etc. I imagine in most of the user-defined cases a backtick fence would be preferred, maybe automatically switching to a snippet if the output is over a certain number of lines.
list-skills
should be returning both names and descriptions, otherwise I might never known what get-thingamajigger
does. While I believe this command would be better suited outputting to a table, I'd like to leave specifying default formatters (JSON, Table, or no-op) in skill definitions (when they're a terminal command in a pipeline) for a later ticket. For commands that spit out text like list-logs
(ls -lAh /var/log
), those will fail JSON parsing and just get spit out as it came in.
Can you explain the use case you have in mind? It seems like JSON is more of a special case than warrants making it the default...
I totally blew this ticket up beyond it's original intention so I'm just going to make a new one. That's probably how I should have done this anyway. 🐮 along; 🙈.
The current output is just a an
inspect
of the map that the function returns. It should be formatted a bit more nicely.This is a followup from #10