kronk icon indicating copy to clipboard operation
kronk copied to clipboard

allow for default parser

Open bhenderson opened this issue 12 years ago • 5 comments

hey there, could you support setting a default parser in the config file?

thanks,

bhenderson avatar Aug 22 '13 16:08 bhenderson

Are you talking about a default parser for a specific content type (e.g. I want my own JSON parser instead of the built-in one) or just a default in general (e.g. I'm only ever dealing with JSON so always use the JSON parser)?

If it's the former, you should be able to define which parser to use for which content-type in the configs: content_types: xml: XMLParser plist: PlistParser json: JSON ...

If it's the latter, because Kronk figures out the parser to use from the returned content-type, it wouldn't make much sense to always use, say JSON. That said, you can definitely set a default parser per host/uri in the configs: uri_options: example.com: :parser: XMLParser

jcasts avatar Aug 22 '13 16:08 jcasts

hey jeremie, thanks

what I'm looking for is if there is no content type, ie

cat json_file | kronk

using -P json works. Maybe allowing for something like that in the config would work. :parser: json

bhenderson avatar Aug 22 '13 18:08 bhenderson

For files, it should know how to parse files if they have the correct extension:

kronk json_file.json

Stdin parsing is tougher. What I've done in the past is just alias the command, which still lets you pass more arguments and options as needed:

alias kjson="kronk -P json"

jcasts avatar Aug 22 '13 18:08 jcasts

Yeah. Sorry. I'm pipping in from some other command not actually a file

On Thursday, August 22, 2013, Jeremie wrote:

If you name your file *.json it should know how to parse it.

— Reply to this email directly or view it on GitHubhttps://github.com/yaks/kronk/issues/24#issuecomment-23114326 .

bhenderson avatar Aug 22 '13 19:08 bhenderson

Some sort of content-type detection might be a solution. Gotta think this one through.

jcasts avatar Aug 20 '14 20:08 jcasts