Skip to content

enable to pass switch values dynamically#11057

Merged
WindSoilder merged 2 commits intonushell:mainfrom
WindSoilder:switch
Nov 22, 2023
Merged

enable to pass switch values dynamically#11057
WindSoilder merged 2 commits intonushell:mainfrom
WindSoilder:switch

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

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 A: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
@WindSoilder
Copy link
Copy Markdown
Contributor 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

A:syntax Changes to the grammar or syntax beyond parser bugfixes semantics Places where we should define/clarify nushell's semantics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it possible to pass boolean flags dynamically

2 participants