Add experimental support for JSON input.
Only supports reading JSON input from stdin for the new subcommand.
Adds a new Parsers class which can implement differing input methods.
Hi @WhyNotHugo,
I have added some experimental code to implement JSON input from stdin for the todoman new command, to show you the direction I am heading.
Currently I am working on having click stop the validation callbacks on the todo_properties arguments after detecting read_json, but my experience with click is very limited. If you have some ideas on how to do that without big changes to the cli, a small hint would be great! It would also be possible to move the functionality to an entirely new subcommand (e.g. todoman new-json).
Thank you for your review! I will implement your suggestions and work on the rest of the functionality.
After some hours researching how to work with Click I believe it would be far easier and less complicated to add a new command or even a new group for working with json input. The current interface is built with command-line-options grouped in reuseable functions returning a decorator. Unfortunately it is impossible to suspend the validation callbacks on these options when the --read-json argument is passed, so I am proposing the following:
Instead of todo --porcelain new --read-json create the new command as todo new-json and analoguous for the edit/update command. Any thoughts?
After thinking about this a bunch of times, I think we can have a new todo import command. Unlike new, import doesn't use @_todo_property_options, doesn't prompt for anything interactively, and doesn't show a UI.
This feature can exist as todo import --json FILE, where FILE can be - to read from stdin.
If --porcelain is provided, we output the todo as JSON, otherwise we print the regular version (e.g.: there's no special behaviour when it comes to output).
Perhaps todo import --ics can be a thing in future, but honestly the main reason for a separate command is the limitations that you mentioned above regarding the decorators in todo new.
After thinking about this a bunch of times, I think we can have a new
todo importcommand. Unlikenew,importdoesn't use@_todo_property_options, doesn't prompt for anything interactively, and doesn't show a UI.
That seems like a good idea to me. The way validation is implemented using Click callbacks, it is very hard to make changes to the UI without breaking existing functionality. A separate json mode for scripted interaction would be great.
This feature can exist as
todo import --json FILE, whereFILEcan be-to read from stdin.If
--porcelainis provided, we output the todo as JSON, otherwise we print the regular version (e.g.: there's no special behaviour when it comes to output).
I will have a look at this 🙂