Skip to content

chore(cli): Add --no-open to cli options - #2643

Closed
drobannx wants to merge 1 commit into
vitejs:mainfrom
drobannx:add_noOpen_cli
Closed

chore(cli): Add --no-open to cli options#2643
drobannx wants to merge 1 commit into
vitejs:mainfrom
drobannx:add_noOpen_cli

Conversation

@drobannx

Copy link
Copy Markdown

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Description

This PR updates the cli options output to add the --no-open option that will prevent the browser from opening on startup.

@drobannx

Copy link
Copy Markdown
Author

@Shinigami92 - Happy to update some types as well but I wasn't 100% sure where --no-open is used. I am assuming they are passed down to another dependency layer that uses this option but I wasn't 100% sure

@patak-cat

Copy link
Copy Markdown
Member

I think that the --no-{option} pattern is a feature of https://github.com/cacjs/cac, no?
if we document something, it should be that this is available for all boolean options

@drobannx

Copy link
Copy Markdown
Author

Ah yeah, I didn't realize that feature was a part of cac but after reading it, that totally makes sense. I'll update the documentation for the cli options to reflect this negation of boolean options.

.option('--port <port>', `[number] specify port`)
.option('--https', `[boolean] use TLS + HTTP/2`)
.option('--open [path]', `[boolean | string] open browser on startup`)
.option('--no-open', `[boolean] prevents browser opening on startup`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as you already found out, this is invalid due to cac provide this by default

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unfortunately don't see an option in cac to provide any kind of global option aside text for all options. There are a couple methods like usage, example, or command description I could leverage but the output isn't the greatest and doesn't seem fit for this use case.

I could use example and show one usage of using the negation option feature of cac?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah oh, so this theoretically overrides just the description text?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is something you could discuss in an issue or discussion in cac @drobannx , maybe they have best practices already

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the change in this PR would only show that additional option but cac does treat the defaults differently in this case.

https://github.com/cacjs/cac#negated-options

So this change would set open to true by default but then passing --no-open as an arg would set the value to false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you got it yourself, but just want to mention it: changing the default value is not an option
The default have to be false in this case

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matias-capeletto - I'll go ahead and close this PR and see if there is some discussion over in cac about this. Thank you and @Shinigami92 for your time in helping with this, I appreciate it!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there already is an open PR over there for this very issue: cacjs/cac#104

@drobannx drobannx closed this Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants