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

Fix:(issue_1197) Set destination field from altsrc for slice flags #1495

Merged
merged 2 commits into from Sep 15, 2022

Conversation

dearchap
Copy link
Contributor

What type of PR is this?

(REQUIRED)

  • bug

What this PR does / why we need it:

(REQUIRED)

Which issue(s) this PR fixes:

(REQUIRED)

Special notes for your reviewer:

(fill-in or delete this section)

Testing

(fill-in or delete this section)

Tested with user provided code. Will add unit tests to confirm this.

Release Notes

(REQUIRED)


@dearchap dearchap requested a review from a team as a code owner September 12, 2022 12:56
@dearchap dearchap marked this pull request as draft September 12, 2022 12:56
@dearchap dearchap marked this pull request as ready for review September 12, 2022 17:41
@Dokiys
Copy link
Member

Dokiys commented Sep 13, 2022

@dearchap Hi, I'm a little confused about Destination, I don't quite understand what it does

@dearchap
Copy link
Contributor Author

Any flags value can be retrieved using ctx.XXXTypeName("flagName") or if the Destination field in the flag is set, that value. For example for

var bar int
ifg := IntFlag{Name: "foo", Destination: &bar}

So if the flag is set on cmdline or from env you could do ctx.Int(foo) of do *ifg.Destination to get the value.

@Dokiys
Copy link
Member

Dokiys commented Sep 14, 2022

Any flags value can be retrieved using ctx.XXXTypeName("flagName") or if the Destination field in the flag is set, that value. For example for

var bar int
ifg := IntFlag{Name: "foo", Destination: &bar}

So if the flag is set on cmdline or from env you could do ctx.Int(foo) of do *ifg.Destination to get the value.

Why not use Value? Is it because it is possible that the Value could be changed? Taking StringSlice as an example, in StringSliceFlag.Apply or StringSliceFlag.ApplyInputSourceValue, the value of Destination is the same as the value of Value:

cli/flag_string_slice.go

Lines 118 to 124 in 9120e06

func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
// apply any default
if f.Destination != nil && f.Value != nil {
f.Destination.slice = make([]string, len(f.Value.slice))
copy(f.Destination.slice, f.Value.slice)
}

@dearchap
Copy link
Contributor Author

Value is supplied by the user and is supposed to represent the default value(s) etc. User could supply a destination or not. So if it is specified it should match the Value

@dearchap dearchap merged commit 880a802 into urfave:main Sep 15, 2022
@meatballhat meatballhat mentioned this pull request Oct 2, 2022
30 tasks
another-rex added a commit to google/osv.dev that referenced this pull request Oct 6, 2022
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[github.com/CycloneDX/cyclonedx-go](https://togithub.com/CycloneDX/cyclonedx-go)
| require | minor | `v0.6.0` -> `v0.7.0` |
|
[github.com/jedib0t/go-pretty/v6](https://togithub.com/jedib0t/go-pretty)
| require | minor | `v6.3.9` -> `v6.4.0` |
| [github.com/urfave/cli/v2](https://togithub.com/urfave/cli) | require
| minor | `v2.16.3` -> `v2.17.1` |
| [golang.org/x/crypto](https://togithub.com/golang/crypto) | require |
digest | `eccd636` -> `4161e89` |
| [golang.org/x/exp](https://togithub.com/golang/exp) | require | digest
| `439092d` -> `b9f4876` |
| [golang.org/x/term](https://togithub.com/golang/term) | require |
digest | `7de9c90` -> `7a66f97` |

---

### Release Notes

<details>
<summary>CycloneDX/cyclonedx-go</summary>

###
[`v0.7.0`](https://togithub.com/CycloneDX/cyclonedx-go/releases/tag/v0.7.0)

[Compare
Source](https://togithub.com/CycloneDX/cyclonedx-go/compare/v0.6.0...v0.7.0)

#### Changelog

##### Features

-
[`acb9322`](https://togithub.com/CycloneDX/cyclonedx-go/commit/acb932270c1594cb44c052ebeacfe4400c25e30b):
feat: add enum for official media types
([@&#8203;nscuro](https://togithub.com/nscuro))
-
[`2826fe2`](https://togithub.com/CycloneDX/cyclonedx-go/commit/2826fe20711931e40df00c2d9058232b6c4ec8af):
feat: add support for encoding to older spec versions
([#&#8203;51](https://togithub.com/CycloneDX/cyclonedx-go/issues/51))
([@&#8203;nscuro](https://togithub.com/nscuro))
-
[`7a2113a`](https://togithub.com/CycloneDX/cyclonedx-go/commit/7a2113a1d5cdbc27b170ce7a487cc13a108950f5):
feat: raise baseline go version to 1.17
([#&#8203;53](https://togithub.com/CycloneDX/cyclonedx-go/issues/53))
([@&#8203;nscuro](https://togithub.com/nscuro))
-
[`7415143`](https://togithub.com/CycloneDX/cyclonedx-go/commit/7415143fe9af48fafb4bd823cfd1dc1aaea9084e):
feat: return error when parsing unknown spec versions
([@&#8203;nscuro](https://togithub.com/nscuro))
-
[`1655b7d`](https://togithub.com/CycloneDX/cyclonedx-go/commit/1655b7dad8bb4e1cc7c402fac75dddf998dc5621):
feat: set `SpecVersion` when decoding from xml
([@&#8203;nscuro](https://togithub.com/nscuro))
-
[`f97e04a`](https://togithub.com/CycloneDX/cyclonedx-go/commit/f97e04a588544317e666deae16fbff4b4b1a89c5):
feat: update gitpod dockerfile
([@&#8203;nscuro](https://togithub.com/nscuro))

##### Fixes

-
[`ea0d5b7`](https://togithub.com/CycloneDX/cyclonedx-go/commit/ea0d5b79fe245884a46d7537271d0d951d46ad1a):
fix: prevent nesting of `Dependency`
([@&#8203;nscuro](https://togithub.com/nscuro))

##### Building and Packaging

-
[`f43660c`](https://togithub.com/CycloneDX/cyclonedx-go/commit/f43660c92e8aa58b574b90395330c2d423d87e54):
build(deps): bump actions/setup-go from 3.1.0 to 3.2.0
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`2458312`](https://togithub.com/CycloneDX/cyclonedx-go/commit/245831215bceb60ad7c0b237819dadf6fb185a4e):
build(deps): bump actions/setup-go from 3.2.0 to 3.2.1
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`760fae3`](https://togithub.com/CycloneDX/cyclonedx-go/commit/760fae3319dd04b9f95659eca5cada2dcedb885e):
build(deps): bump actions/setup-go from 3.2.1 to 3.3.0
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`4dddf51`](https://togithub.com/CycloneDX/cyclonedx-go/commit/4dddf51ddd4be68d6c0f35adef628acd36eae0ab):
build(deps): bump apache/skywalking-eyes from 0.3.0 to 0.4.0
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`6eb6521`](https://togithub.com/CycloneDX/cyclonedx-go/commit/6eb6521f71afc72eef65bf97033e1197a778ddab):
build(deps): bump github.com/bradleyjkemp/cupaloy/v2 from 2.7.0 to 2.8.0
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`bff00ef`](https://togithub.com/CycloneDX/cyclonedx-go/commit/bff00ef23cf6cdcd520c179f995aabc83cc955b9):
build(deps): bump github.com/stretchr/testify from 1.7.1 to 1.7.2
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`fc11b56`](https://togithub.com/CycloneDX/cyclonedx-go/commit/fc11b56380ce3c547d34194a39c3ef736e6c8397):
build(deps): bump github.com/stretchr/testify from 1.7.2 to 1.7.4
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`f521d75`](https://togithub.com/CycloneDX/cyclonedx-go/commit/f521d75e187d6f2ca3ce289cfa4afbd961b04402):
build(deps): bump github.com/stretchr/testify from 1.7.4 to 1.7.5
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`d5d1ab6`](https://togithub.com/CycloneDX/cyclonedx-go/commit/d5d1ab6ca40e8ef882d6e51e1ebcb4ce72fcb805):
build(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])
-
[`b83bbe8`](https://togithub.com/CycloneDX/cyclonedx-go/commit/b83bbe808f6545654d4e0deecc7e7806a2e49c4e):
build(deps): bump goreleaser/goreleaser-action from 2 to 3
([@&#8203;dependabot](https://togithub.com/dependabot)\[bot])

##### Documentation

-
[`8f8fadf`](https://togithub.com/CycloneDX/cyclonedx-go/commit/8f8fadfe296ad32dd78f513cd7475e81ed85e200):
docs: fix cyclonedx-go version in compatibility matrix
([@&#8203;nscuro](https://togithub.com/nscuro))
-
[`124f2be`](https://togithub.com/CycloneDX/cyclonedx-go/commit/124f2be91434d720dd5d3149d7ab04461405c207):
docs: fix typos ([@&#8203;nscuro](https://togithub.com/nscuro))

##### Others

-
[`5f10aea`](https://togithub.com/CycloneDX/cyclonedx-go/commit/5f10aea00cf46bbe3a4ce66ce2b85bd17576a35c):
refactor: refine spec version conversion to cover more cases
([@&#8203;nscuro](https://togithub.com/nscuro))
-
[`0c2ebff`](https://togithub.com/CycloneDX/cyclonedx-go/commit/0c2ebff85af58497076969010e3bb29f62f19f16):
refactor: separate custom marshalling logic from model
([@&#8203;nscuro](https://togithub.com/nscuro))

</details>

<details>
<summary>jedib0t/go-pretty</summary>

###
[`v6.4.0`](https://togithub.com/jedib0t/go-pretty/releases/tag/v6.4.0)

[Compare
Source](https://togithub.com/jedib0t/go-pretty/compare/v6.3.9...v6.4.0)

### Features

-   **progress**
- option to set Pinned Message(s) above active Trackers (thanks to
[@&#8203;iyear](https://togithub.com/iyear))

</details>

<details>
<summary>urfave/cli</summary>

### [`v2.17.1`](https://togithub.com/urfave/cli/releases/tag/v2.17.1)

[Compare
Source](https://togithub.com/urfave/cli/compare/v2.17.0...v2.17.1)

#### What's Changed

- Fix help results inconsistency by
[@&#8203;dearchap](https://togithub.com/dearchap) in
[urfave/cli#1499

**Full Changelog**:
urfave/cli@v2.17.0...v2.17.1

### [`v2.17.0`](https://togithub.com/urfave/cli/releases/tag/v2.17.0)

[Compare
Source](https://togithub.com/urfave/cli/compare/v2.16.6...v2.17.0)

#### What's Changed

- Flag-level Action by [@&#8203;xwjdsh](https://togithub.com/xwjdsh) in
[urfave/cli#1337

#### New Contributors

- [@&#8203;xwjdsh](https://togithub.com/xwjdsh) made their first
contribution in
[urfave/cli#1337

**Full Changelog**:
urfave/cli@v2.16.6...v2.17.0

### [`v2.16.6`](https://togithub.com/urfave/cli/releases/tag/v2.16.6)

[Compare
Source](https://togithub.com/urfave/cli/compare/v2.16.5...v2.16.6)

#### What's Changed

- fix: Context.Set no such flag by
[@&#8203;Torwang1](https://togithub.com/Torwang1) in
[urfave/cli#1497

#### New Contributors

- [@&#8203;Torwang1](https://togithub.com/Torwang1) made their first
contribution in
[urfave/cli#1497

**Full Changelog**:
urfave/cli@v2.16.5...v2.16.6

### [`v2.16.5`](https://togithub.com/urfave/cli/releases/tag/v2.16.5)

[Compare
Source](https://togithub.com/urfave/cli/compare/v2.16.4...v2.16.5)

#### What's Changed

- Fix:(issue\_1197) Set destination field from altsrc for slice flags by
[@&#8203;dearchap](https://togithub.com/dearchap) in
[urfave/cli#1495

**Full Changelog**:
urfave/cli@v2.16.4...v2.16.5

### [`v2.16.4`](https://togithub.com/urfave/cli/releases/tag/v2.16.4)

[Compare
Source](https://togithub.com/urfave/cli/compare/v2.16.3...v2.16.4)

#### What's Changed

- Accept the `MKDOCS_REMOTE_GITHUB_TOKEN` var as intended by
[@&#8203;meatballhat](https://togithub.com/meatballhat) in
[urfave/cli#1493

**Full Changelog**:
urfave/cli@v2.16.3...v2.16.4

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 6am on monday" in timezone
Australia/Sydney, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click
this checkbox.

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/google/osv.dev).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4yMTMuMCIsInVwZGF0ZWRJblZlciI6IjMyLjIxNi4wIn0=-->

Co-authored-by: Rex P <106129829+another-rex@users.noreply.github.com>
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.

None yet

2 participants