Skip to content
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

enable to pass switch values dynamically #11057

Merged
merged 2 commits into from Nov 22, 2023
Merged

Conversation

WindSoilder
Copy link
Collaborator

Description

Closes: #7260

About the change:
When we make an internalcall, and meet a switch (Flag.arg is None), nushell will try to see if the switch is called like --xyz=false , if that is true, parse_long_flag will return relative value.

User-Facing Changes

So after the pr, the following would be possible:

def build-imp [--push, --release] {
    echo $"Doing a build with push: ($push) and release: ($release)"
}
def build [--push, --release] {
    build-imp --push=$push --release=$release
}

build --push --release=false
build --push=false --release=true
build --push=false --release=false
build --push --release
build

Tests + Formatting

Done

After Submitting

Needs to submit a doc update, mentioned about the difference between def a [--x] {} and def a [--x: bool] {}

@sholderbach sholderbach added semantics Places where we should define/clarify nushell's semantics syntax Changes to the grammar or syntax beyond parser bugfixes labels Nov 15, 2023
@WindSoilder WindSoilder merged commit 6cfe35e into nushell:main Nov 22, 2023
19 checks passed
@WindSoilder
Copy link
Collaborator Author

After discussing, I think we can merge and try it first

amtoine added a commit to amtoine/nu-git-manager that referenced this pull request Nov 24, 2023
related to
- nushell/nushell#11057

## description
this PR simplifies the switch forwarding in `gm gh query-user` and `gm
gh query-releases` to `gm gh query-api` with the following syntax from
nushell/nushell#11057
```nushell
foo --bar=$bar
```
amtoine added a commit to amtoine/nu-git-manager that referenced this pull request Dec 13, 2023
related to
- nushell/nushell#11057

## description
this PR simplifies the switch forwarding in `gm gh query-user` and `gm
gh query-releases` to `gm gh query-api` with the following syntax from
nushell/nushell#11057
```nushell
foo --bar=$bar
```
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# Description
Closes: nushell#7260 

About the change:
When we make an internalcall, and meet a `switch` (Flag.arg is None),
nushell will try to see if the switch is called like `--xyz=false` , if
that is true, `parse_long_flag` will return relative value.

# User-Facing Changes
So after the pr, the following would be possible:
```nushell
def build-imp [--push, --release] {
    echo $"Doing a build with push: ($push) and release: ($release)"
}
def build [--push, --release] {
    build-imp --push=$push --release=$release
}

build --push --release=false
build --push=false --release=true
build --push=false --release=false
build --push --release
build
```

# Tests + Formatting
Done

# After Submitting
Needs to submit a doc update, mentioned about the difference between
`def a [--x] {}` and `def a [--x: bool] {}`
amtoine added a commit that referenced this pull request Dec 21, 2023
# Description
While #11057 is merged, it's hard to tell the difference between
`--flag: bool` and `--flag`, and it makes user hard to read custom
commands' signature, and hard to use them correctly.

After discussion, I think we can deprecate `--flag: bool` usage, and
encourage using `--flag` instead.

# User-Facing Changes
The following code will raise warning message, but don't stop from
running.
```nushell
❯ def florb [--dry-run: bool, --another-flag] { "aaa" };  florb
Error:   × Deprecated: --flag: bool
   ╭─[entry #7:1:1]
 1 │ def florb [--dry-run: bool, --another-flag] { "aaa" };  florb
   ·                       ──┬─
   ·                         ╰── `--flag: bool` is deprecated. Please use `--flag` instead, more info: https://www.nushell.sh/book/custom_commands.html
   ╰────

aaa
```

cc @kubouch 

# Tests + Formatting
Done

# After Submitting
- [ ] Add more information under
https://www.nushell.sh/book/custom_commands.html to indicate `--dry-run:
bool` is not allowed,
- [ ] remove `: bool` from custom commands between 0.89 and 0.90

---------

Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
@WindSoilder WindSoilder deleted the switch branch January 2, 2024 13:35
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Closes: nushell#7260 

About the change:
When we make an internalcall, and meet a `switch` (Flag.arg is None),
nushell will try to see if the switch is called like `--xyz=false` , if
that is true, `parse_long_flag` will return relative value.

# User-Facing Changes
So after the pr, the following would be possible:
```nushell
def build-imp [--push, --release] {
    echo $"Doing a build with push: ($push) and release: ($release)"
}
def build [--push, --release] {
    build-imp --push=$push --release=$release
}

build --push --release=false
build --push=false --release=true
build --push=false --release=false
build --push --release
build
```

# Tests + Formatting
Done

# After Submitting
Needs to submit a doc update, mentioned about the difference between
`def a [--x] {}` and `def a [--x: bool] {}`
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
While nushell#11057 is merged, it's hard to tell the difference between
`--flag: bool` and `--flag`, and it makes user hard to read custom
commands' signature, and hard to use them correctly.

After discussion, I think we can deprecate `--flag: bool` usage, and
encourage using `--flag` instead.

# User-Facing Changes
The following code will raise warning message, but don't stop from
running.
```nushell
❯ def florb [--dry-run: bool, --another-flag] { "aaa" };  florb
Error:   × Deprecated: --flag: bool
   ╭─[entry nushell#7:1:1]
 1 │ def florb [--dry-run: bool, --another-flag] { "aaa" };  florb
   ·                       ──┬─
   ·                         ╰── `--flag: bool` is deprecated. Please use `--flag` instead, more info: https://www.nushell.sh/book/custom_commands.html
   ╰────

aaa
```

cc @kubouch 

# Tests + Formatting
Done

# After Submitting
- [ ] Add more information under
https://www.nushell.sh/book/custom_commands.html to indicate `--dry-run:
bool` is not allowed,
- [ ] remove `: bool` from custom commands between 0.89 and 0.90

---------

Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semantics Places where we should define/clarify nushell's semantics syntax Changes to the grammar or syntax beyond parser bugfixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to pass boolean flags dynamically
2 participants