-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for reading command-line options from file(s) (#191) #317
base: master
Are you sure you want to change the base?
Add support for reading command-line options from file(s) (#191) #317
Conversation
💵 To receive payouts, sign up on Algora, link your Github account and connect with Stripe/Alipay. |
Let me know if the code implementation is acceptable, and if so, I will add docs for it. |
e7f5c96
to
042fe3b
Compare
@pablf ccing you here because wasnt able to properly @ you in discord |
@Kalin-Rudnicki Hi, it looks good! Just in case, the docs refer to the docs displayed by the CLI, not the library documentation. I like the flexibility of allowing to add your custom |
"test-app", | ||
"v0", | ||
HelpDoc.Span.empty, | ||
Command("cmd", options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test other CliApps
with more complex commands? One Command
using all the combinators should be enough. And if you could also test when using also Args
and only Args
with no Options
, that would be great.
@@ -0,0 +1,5 @@ | |||
package zio.cli | |||
|
|||
trait FileArgsPlatformSpecific { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be private[cli]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean
private[cli] trait FileArgsPlatformSpecific {
or
trait FileArgsPlatformSpecific private[cli] {
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did the first one, looked at other *PlatformSpecifc
args: List[String], | ||
fromFiles: List[FileArgs.ArgsFromFile], | ||
conf: CliConfig | ||
): IO[ValidationError, CommandDirective[A]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better to have fromFiles
as the third parameter with a default value. Probably it's sign of a bad use, but there might be someone calling directly this method and would be a breaking change. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable
@@ -306,12 +369,15 @@ object Options extends OptionsPlatformSpecific { | |||
def validate[A]( | |||
options: Options[A], | |||
args: List[String], | |||
fromFiles: List[FileArgs.ArgsFromFile], | |||
conf: CliConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing with fromFiles
as last parameter.
import zio._ | ||
import java.nio.file.Path | ||
|
||
trait FileArgs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change Args
for something referring to Options
because this represents Options
from files and there are both Options
and Args
in zio-cli
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call
import java.nio.file.{Files, Path} | ||
|
||
object LiveFileArgsSpec extends ZIOSpecDefault { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be put also in the native
folder, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add this, yes.
I am really annoyed... Intellij creates multiple cross-platform directories:
js-jvm
js-native
jvm-native
But sbt doesnt seem to correctly add these dependencies as I would expect.
I tried originally adding this spec injvm-native
, but it didnt seem to realize anything inshared
existed :/
@pablf can you please advise where you would recommend adding notes about |
@pablf After trying to add tests for more complex commands, I realized that I think its sub-par to do Because you could have something like: command1 | command2 and then you would be looking for an indeterminate one of Im not super familiar with this library, but IMO, it seems to me that As I mentioned, this would be a pretty large change, and I don't really want to go through that, even if you agreed it was a better model. Also, it seems a bit strange to do something like val cmd1: Command[?] = ??? // complex command with orElse and subCommands
val cmd2: Command[?] = ??? // complex command with orElse and subCommands
(cmd1 | cmd2).subCommands(???)
cmd1.subCommands(cmd2).subCommands(???) |
@Kalin-Rudnicki The cli library parse and shows the help command in Regarding the design of val cmd1 = ???
val cmd2 = ???
val cmd3 = ???
val cmd4 = ???
val cmd = (cmd1 | cmd2).subcommands(cmd3 | cmd4) so you can use all the following commands:
I think that the best way to implement this feature given the situation is to parse the command and, once you know which one is the top-level command, to retrieve the file options. This or just to allow this feature for commands with an unique top-level command. Maybe @jdegoes wants to share his thoughts on this. |
Im going to pursue the |
Does this seem reasonable, or do you have any recommendations of how to phrase it more clearly/concisely:
|
/claim #191