-
Notifications
You must be signed in to change notification settings - Fork 18
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
allow "attach" and "down" subcommands to work, show it in ponysay example #82
Conversation
Dang, my first attempt also didn't work, because the test always adds arguments and therefore the wrapper thought it's not the "up" command. I've committed the possible solution. But if you prefer to go with the previous strategy, then the "-t=false" argument probably needs to be added inside |
params=(${cliOutputs.global}) | ||
set +u | ||
if [ -z "$1" ] || [[ "$1" == "up" ]] || [[ "$1" == -* ]] ; then | ||
params+=(--config ${configFile} ${cliOutputs.up}) |
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.
In the "$1" == "up"
case, shouldn't you drop the up
from $@
? Otherwise, in line 60 it will be passed twice.
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.
No, we're passing the arguments on as we receive them, and we never add an "up" ourselves afaik
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.
You are right:
❮ nix run --override-input process-compose-flake .. .#default -- up --log-file=output.log
[...]
+ process-compose --no-server --config /nix/store/bl46rll1p24g5fbdypbxsk6rfnklfp2z-process-compose-default.json --disable-dotenv --theme Cobalt up --log-file=output.log
But then, I just noticed something new here. Note that --disable-dotenv --theme Cobalt
(defined in cli.up
) appears before the up
argument. It looks like their CLI parser accepts this out of order arguments anyway. But for clarity, I'd prefer that --disable-dotenv --theme Cobalt
appear after the up
argument, because those options are meant for up
subcommand anyway.
Suppressing incorrect observation
Wait, I was wrong. Actually those are global options! We should fix this in options.--sort
however is an is another example:up
specific option, so that's a better illustration
--- a/example/flake.nix
+++ b/example/flake.nix
@@ -30,8 +30,7 @@
};
# Options for `process-compose up`
up = {
- disable-dotenv = true;
- theme = "Cobalt";
+ sort = "health";
};
};
settings = {
Without arguments, we see:
❯ nix run --override-input process-compose-flake .. .#default
[..]
+ process-compose --no-server --config /nix/store/bl46rll1p24g5fbdypbxsk6rfnklfp2z-process-compose-default.json --sort health
(And I'd still like to make up
implicit here)
With up
argument:
❯ nix run --override-input process-compose-flake .. .#default up
+ process-compose --no-server --config /nix/store/bl46rll1p24g5fbdypbxsk6rfnklfp2z-process-compose-default.json --sort health up
Here, I think --sort health
should appear after up
to make it clear (to the user who happens to diagnose our script output) that these flags are for up
command only.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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 agree, it's better to put user arguments first. I've changed that.
Found some bugs:
|
# Otherwise, we assume it's a subcommand other than "up" | ||
params=(${cliOutputs.global}) | ||
set +u | ||
if [ -z "$1" ] || [[ "$1" == "up" ]] || [[ "$1" == -* ]] ; then |
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 don't see what purpose [[ "$1" == -* ]]
serves here.
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 tried to explain it in the comments, but it looks like it failed 😅
If the first argument starts with a dash, we know it's no subcommand. And if the first argument is no subcommand, we assume there is no subcommand argument at all. And if there is none, process-compose defaults to the up command. And therefore it's allowed to pass arguments dedicated to the up command.
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 understood the what, but I'm asking why.
If the first argument starts with a dash, we assume there isn't a subcommand, so it's also the "up" command
This is of course wrong, since --help
is not equivalent to up
.
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.
Yes, that seems to be one of the edge cases I mentioned. Properly dealing with it could be tricky, though. Any ideas?
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.
Why not remove [[ "$1" == -* ]]
entirely?
Interesting.. I'll have to look into that. But I think we won't be able to make it work for 100% of the cases, we would have to build a proper wrapper for that, that can parse the arguments the same way process compose does. |
Or you can just remove the |
It's there to be compliant with the original CLI. If you don't pass "up" there, it still will start the processes. It will still try to do that if we remove that part, but it won't get any arguments (like --config) and therefore fail. |
Can you be a little more concrete? Specifically, for this diff, --- a/nix/process-compose/default.nix
+++ b/nix/process-compose/default.nix
@@ -52,7 +52,7 @@ in
# Otherwise, we assume it's a subcommand other than "up"
params=(${cliOutputs.global})
set +u
- if [ -z "$1" ] || [[ "$1" == "up" ]] || [[ "$1" == -* ]] ; then
+ if [ -z "$1" ] || [[ "$1" == "up" ]] ; then
params+=(--config ${configFile} ${cliOutputs.up})
fi ... which particular invocation of the example is problematic (such as to warrant the justification of For example, I ran it without any arguments, and it works just fine:
|
Ah, yeah, I see where the confusion is coming from now. It's all fine if you don't pass any parameters.Because of So try running |
Let's just have the user explicitly pass
|
Yes, I also think it's a good idea to require explicitly providing the subcommand. But shouldn't we communicate this to the user somehow, so that they know what's going on? And for consistency, I think it's best to then also require "up" when no arguments get passed. So, |
I've implemented my suggested solution and I'm personally pretty happy with it. Apart from requiring a subcommand as the first argument, we're fully compatible with all other argument constellations this way. |
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.
Upstream already uses up
as default when none is provided:
❯ , process-compose --config /nix/store/ysw18q5xn937rlf8pf7zi2xjrwmcpmpd-process-compose-process-compose.json
24-10-20 08:23:50.432 FTL start http server on :8080 failed error="listen tcp :8080: bind: address already in use"
We do the same of course. nix run .#foo
(without arguments) should just work in that it should spin up the processes. But the last commit broke it:
❯ just ex
cd ./example && nix run --override-input process-compose-flake ..
warning: not writing modified lock file of flake 'git+file:///Users/srid/code/process-compose-flake?dir=example':
• Updated input 'process-compose-flake':
'github:Platonic-Systems/process-compose-flake/d0824dab6ff49a06ed10e48177aabaef52469a0a' (2024-09-30)
→ 'git+file:///Users/srid/code/process-compose-flake?ref=refs/heads/VanCoding/main&rev=58d976ed053413421ac478debe0d4bdbcb38f1b8' (2024-10-20)
process-compose-flake requires a subcommand like 'up' as the first argument. Configured subcommand cli options are ignored otherwise.
To get a list about available subcommands, use the 'help' subcommand
error: Recipe `ex` failed on line 19 with exit code 1
I'm aware of that, and the previous version took pretty good care of that. Then we decided to break upstream and require specifying a subcommand. If the goal is to not break things, we can just revert. |
I never agree to that, no.
I'm okay with breaking backwards compat if there's significant value in the change; in this case, there's no value whatsoever (if only, it adds to inconvenience of the user). |
You said
That's a breaking change. Upstream did allow passing arguments without providing the subcommand. |
… instructions otherwise" This reverts commit 58d976e.
Oh, I see the misunderstanding. What I meant was that if -- and only if -- the user is going to pass options specific to the i.e., don't support:
but do support:
(especially as explicit is better than implicit) all the while, the following still works as before:
as does:
which this PR adds support for.
If you mean that By the way, it just occurred to me that that |
So it looks like we should just go back to |
I think The actual problem we're dealing with, is that process-compose complains when arguments are passed to a subcommand the arguments are not meant for. So if we pass Now back to the previous topic:
I understand that you don't want to overcomplicate code. That's reasonable. And, frankly, as a user, I'd be really confused why So, the question seems to be where to draw the line between not breaking and keeping the code simple. You seem to have found that answer already with just not supporting any additional args when no subcommand is specified. For me it's the code how it currently is, since it adds a bit more compatibility and isn't really that much more complex (IMO of course). I think the issue is clear now, including the possible solutions and their pros & cons. And it's probably fine to have different opinions on this. Let's just make a decision and tick it off :) |
I appreciate the explanation. I agree with most of it.
Yes, I believe using
You seem to have misinterpreted my suggestion. I suggested using env var only for the config file (ie., However, our problem here is that with this design it becomes impossible to apply To conclude, we should probably get rid of the The original logic was: The new one would be similar to this: export PC_CONFIG_FILES=${configFile}
# This includes PC_DISABLE_TUI
${lib.concatStringsMapSep "\n" (k: v: "export $k=$v") config.extraEnv)
${preHook}
set -x; process-compose ${cliOutputs.global} "$@"; set +x Which is much simpler overall. |
@srid oh, ok if all up-arg options are removed again it's a different story, sure. It would be sad to not have these options, though. There are some useful ones like In the end, fortunately, the wrapper can be wrapped again to re-add this logic, which I'd probably do then for my projects. |
Yup, let's do that. |
|
As a follow up to my last comment here: #81 (comment)
Currently it's not possible to use the "attach" and "down" (and probably all other) subcommands, because they don't allow the "--config" argument, which currently is passed all the time.
This PR is a possible fix to this, with the following drawback: explicitly setting the "up" command will not work, and it also won't work to pass any additional parameters.
I originally wanted to propose the following solution, which would be a bit better, but still not perfect:
VanCoding@5b66d08
That solution would require the subcommand to be the first parameter. But that's probably something the users could live with.