-
Notifications
You must be signed in to change notification settings - Fork 185
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
fixed start-app false when generating openapi file #579
Conversation
Specifically on the main branch: Calling the following with a couple of IO.inspects: (see: test/mix/tasks/openapi.spec.json_test.exs) Mix.Tasks.Openapi.Spec.Json.run(~w(
--quiet=true
--start-app=false
--spec OpenApiSpexTest.Tasks.SpecModule
tmp/openapi.json
)) # The modified task with added inspect calls
def run(argv) do
IO.inspect(argv, label: :ARGV)
{opts, _, _} = IO.inspect(OptionParser.parse(argv, strict: [start_app: :boolean]), label: :OPTS)
# omitted
end Prints:
So @spinettaro In the PR description you have:
Can you please clarify what you mean? Why would it parse assigned values when the key is not present? |
Hi @zorbash :)
It does not work if I run the I need to understand why the above is not working, I'll keep you posted |
@zorbash thoughts ? In addition what made me think about If you ask the tool to convert to ARGV |
The problem you're facing with With This is what phoenix uses here and here. Example: # File test.exs
OptionParser.parse(System.argv(), strict: [start_app: :boolean, other: :boolean])
|> IO.inspect() % elixir test.exs --no-start-app
# {[start_app: false], [], []} Given there's a clear path to the desired behaviour without making any code change, I'm closing this. |
@zorbash the problem is not related to powershell. It is not good to close this one, as the bug is still there. If you use the command provided |
based on the reply on the official Elixir project elixir-lang/elixir#13197 (comment), this PR is more than valid and it is the proper way to do it. |
Claiming that it never worked before is a strong statement unfortunately not backed by equally strong evidence. This can offend the people who have contributed this feature and anybody who has tested it. You can test it on this replit which runs in on Linux and [email protected]. Your PR introduces unnecessary changes, specifically changing how options are parsed from What's worth changing though is the docs, to suggest the recommended way of providing boolean flags, so mentioning |
I'm sorry if my reply was misunderstood. I did not want to underestimate the work other people did before and I'm grateful of it. It was just in the context of backward compatibility. Given the fact it did not work, there is no reason to think about backward compatibility. I demonstrated that That is not to underestimate the work done here, that is great! But to make it better, I think this is also the purpose of an open source project. We can discuss, collaborate, and decide how to make it better. |
However, even on replit it does not work The issue is that when they are passed as real cmd arguments, It worked for you because you were somehow hacking the arguments by passing something like |
@spinettaro You're now accusing me of somehow hacking the arguments 🤯. You can fork and inspect the code of the repl.it link I shared, there's nothing hacky going on. There are also tests in the elixir codebase for this scenario, so please don't misquote Wojtek's comment who never said it's not possible to assign a false value. |
My bad, my answer
|
Thanks so much for chiming in @wojtekmach. Just to clarify further, is the following by any means an Elixir / OptionParser anti-pattern or discouraged for booleans? elixir main.exs --foo=false |
Hi @zorbash ! Don't take it wrong, please :) I'm not trying to accuse anyone and something might go lost in translation as I'm not an English native speaker. No one is accusing you and my bad if you feel it. As you can see from Wojtekmach there was a misunderstanding on the answer and that caused a little bit of confusion. When I wrote hacking your tests I meant What I'm trying to solve is the following:
Hopefully, it is more clear now and @wojtekmach can help with some inputs. |
fixes #489 .
The fix implements a proper usage of
OptionParser
. When it usesboolean
it is not able to understand assigned values liketrue
orfalse
but only if the key is present. The alternative is to useswitches
where you can prefixno
to the existing key to switch the value to false or another approach is to handle it as a string and check for the passed value if it is=false
. I implemented the one usingswthces