j178 / leetgo

Best LeetCode friend for geek. :snowboarder:
MIT License
534 stars 31 forks source link

[Feature Request] Add property based info-alike command with unformatted output #283

Closed whjum closed 6 months ago

whjum commented 6 months ago

The original info command's ouput works well with a human reader. However, it is not working well with cli command as the user need to remove formatting character themselves to obtain the actual data. For example:

$ leetgo info 1 | grep Slug
 Slug        two-sum                                            

In the above use case, I think a query alike command that prints unformatted output with property filter like slug, title, tags, testcase,etc will be helpful.

The query could using the following format: leetgo query qid [property]. For example:

$ leetgo query 1 slug
two-sum

I created a fork to demo one draft of the query command. There should be a better way to map the property of the question struct than the naive switch function. If you have a better approach, I am happy to adapt that.

Kindly let me know if you are interested in adding this command or there might be some better approaches! I am happy to be of help if possible.

Also, thank you sincerely for this wonderful tool! It makes my life a lot eaiser :)

j178 commented 6 months ago

Thanks, I think this is a valid use case for info command.

Instead of adding a new query, I'm thinking adding a --format=json flag to info, which output in JSON format, then we can use leetgo info 1 | jq '.slug' to extract any field you need.

What do you think?

whjum commented 6 months ago

That works as well and maybe easier to implement.

I am thinking instead of using --format=json, a bool flag --raw might be good enough? If you would like to support more than one output formats, probably a string flag will be helpful.

j178 commented 6 months ago

--format=json is more like a convention, many tools support raw output using this flag, --raw is not that common.

whjum commented 6 months ago

No problem. I have some idea and probably can create a pull request to implement that. If you would like to do it yourself, I can also wait for a new release :)

j178 commented 6 months ago

I would like to welcome a new contributor 😄