vivasvan1 / zio-cli

Rapidly build powerful command-line applications powered by ZIO
https://zio.dev/zio-cli
Apache License 2.0
0 stars 0 forks source link

Sweep: Add support for reading command-line options from file(s) #191 #2

Open vivasvan1 opened 1 year ago

vivasvan1 commented 1 year ago

The users command-line app has a top-level command, whose name is <name>.

For example, if the user was creating a word count CLI, then their top-level command name might be wc.

ZIO CLI should examine the following locations to check for the existence of .<name> files:

  1. The current working directory.
  2. All parents of the current working directory.
  3. The user's home directory.

So, in the wc example, if run from /c/Users/john directory, then ZIO CLI would look in the following locations for the existence of .wc files:

  1. /c/Users/john
  2. `/c/Users/
  3. /c/
  4. ~ (user home, probably /c/Users/john on Windows)

Then, ZIO CLI should concatenate these options, with user home having the lowest priority, and the current working directory having the highest priority (so, for example, you can override options in higher priority locations).

Then, ZIO CLI should utilize those command-line options when the program is run, and not require those options be specified. However, if any option is specified on the command-line, then it must override even the highest priority setting specified in the settings files.

An example, let's say wc has an option --line-ending. Then in the .wc file, there might exist:

--line-ending=\n

Then this would be the default line ending. The user would not have to specify it on the command-line. But if the user did specify it on the command-line, it would override the one in the file.

This new functionality should be documented in the help docs for the CLI. Moreover, all of the settings that are picked up from any of the files need to be printed out, so the user can understand exactly where they are coming from.

For the full functionality, implemented in a cross-platform setting, with full test suites, and descriptive help docs, and diagnostics.

Checklist - [ ] ``zio-cli/shared/src/main/scala/zio/cli/CliApp.scala`` - [ ] ``zio-cli/shared/src/main/scala/zio/cli/HelpDoc.scala`` ![2_flowchart.svg](http://24.199.78.105:8082/public/021e9738ddccecf1df27ceaa4625f3b517e7d7dcb8c64e6fd825c161c18b7b52_2_flowchart.svg)
sweep-ai[bot] commented 1 year ago
Sweeping

50%

Actions (click)


❌ Unable to Complete PR

Sorry, I could not edit zio-cli/shared/src/main/scala/zio/cli/CliApp.scala as this file is too long.

If this file is incorrect, please describe the desired file in the prompt. However, if you would like to edit longer files, consider upgrading to Sweep Pro for longer context lengths.

For bonus GPT-4 tickets, please report this bug on Discord (tracking ID: 34ea15cbe9).


Please look at the generated plan. If something looks wrong, please add more details to your issue.

File Path Proposed Changes
zio-cli/shared/src/main/scala/zio/cli/CliApp.scala Modify zio-cli/shared/src/main/scala/zio/cli/CliApp.scala with contents:
Add support for reading command-line options from files in the CliApp class.

1. Create a new method loadOptionsFromFile in the CliApp class that takes the name of the top-level command as a parameter.
2. Inside the loadOptionsFromFile method, implement the logic to examine the specified locations (current working directory, parent directories, and user's home directory) for the existence of .wc files (or files with the name of the top-level command).
3. Read the options specified in the files and store them in a data structure.
4. Modify the CliApp class to utilize the options from the files as default values when running the program.
5. Ensure that options specified on the command-line override the options from the files, even if the options from the files have higher priority.
6. Print out the settings picked up from the files for user reference.
7. Update the documentation in docs/index.md and README.md to include the new functionality and provide instructions on how to use it.
zio-cli/shared/src/main/scala/zio/cli/HelpDoc.scala Modify zio-cli/shared/src/main/scala/zio/cli/HelpDoc.scala with contents:
Update the HelpDoc class to include the settings picked up from the files in the generated help documentation.

1. Modify the HelpDoc class to accept an additional parameter for the settings picked up from the files.
2. Update the generated help documentation to include the settings picked up from the files.

πŸŽ‰ Latest improvements to Sweep:


πŸ’‘ To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.