Skip to content

Commit

Permalink
Fix build for go < 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycumines committed Jun 12, 2022
1 parent e77dd7b commit 4f795e3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 60 deletions.
15 changes: 0 additions & 15 deletions flag_float64_slice.go
Expand Up @@ -164,21 +164,6 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

func (f *Float64SliceFlag) SetValue(slice []float64) {
f.Value = newSliceFlagValue(NewFloat64Slice, slice)
}

func (f *Float64SliceFlag) SetDestination(slice []float64) {
f.Destination = newSliceFlagValue(NewFloat64Slice, slice)
}

func (f *Float64SliceFlag) GetDestination() []float64 {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}

// Get returns the flag’s value in the given Context.
func (f *Float64SliceFlag) Get(ctx *Context) []float64 {
return ctx.Float64Slice(f.Name)
Expand Down
15 changes: 0 additions & 15 deletions flag_int64_slice.go
Expand Up @@ -163,21 +163,6 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

func (f *Int64SliceFlag) SetValue(slice []int64) {
f.Value = newSliceFlagValue(NewInt64Slice, slice)
}

func (f *Int64SliceFlag) SetDestination(slice []int64) {
f.Destination = newSliceFlagValue(NewInt64Slice, slice)
}

func (f *Int64SliceFlag) GetDestination() []int64 {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}

// Get returns the flag’s value in the given Context.
func (f *Int64SliceFlag) Get(ctx *Context) []int64 {
return ctx.Int64Slice(f.Name)
Expand Down
15 changes: 0 additions & 15 deletions flag_int_slice.go
Expand Up @@ -174,21 +174,6 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

func (f *IntSliceFlag) SetValue(slice []int) {
f.Value = newSliceFlagValue(NewIntSlice, slice)
}

func (f *IntSliceFlag) SetDestination(slice []int) {
f.Destination = newSliceFlagValue(NewIntSlice, slice)
}

func (f *IntSliceFlag) GetDestination() []int {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}

// Get returns the flag’s value in the given Context.
func (f *IntSliceFlag) Get(ctx *Context) []int {
return ctx.IntSlice(f.Name)
Expand Down
15 changes: 0 additions & 15 deletions flag_string_slice.go
Expand Up @@ -152,21 +152,6 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

func (f *StringSliceFlag) SetValue(slice []string) {
f.Value = newSliceFlagValue(NewStringSlice, slice)
}

func (f *StringSliceFlag) SetDestination(slice []string) {
f.Destination = newSliceFlagValue(NewStringSlice, slice)
}

func (f *StringSliceFlag) GetDestination() []string {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}

// Get returns the flag’s value in the given Context.
func (f *StringSliceFlag) Get(ctx *Context) []string {
return ctx.StringSlice(f.Name)
Expand Down
65 changes: 65 additions & 0 deletions sliceflag.go
@@ -1,3 +1,6 @@
//go:build go1.18
// +build go1.18

package cli

import (
Expand Down Expand Up @@ -226,3 +229,65 @@ func unwrapFlagValue(v flag.Value) flag.Value {
v = h.value
}
}

// NOTE: the methods below are in this file to make use of the build constraint

func (f *Float64SliceFlag) SetValue(slice []float64) {
f.Value = newSliceFlagValue(NewFloat64Slice, slice)
}

func (f *Float64SliceFlag) SetDestination(slice []float64) {
f.Destination = newSliceFlagValue(NewFloat64Slice, slice)
}

func (f *Float64SliceFlag) GetDestination() []float64 {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}

func (f *Int64SliceFlag) SetValue(slice []int64) {
f.Value = newSliceFlagValue(NewInt64Slice, slice)
}

func (f *Int64SliceFlag) SetDestination(slice []int64) {
f.Destination = newSliceFlagValue(NewInt64Slice, slice)
}

func (f *Int64SliceFlag) GetDestination() []int64 {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}

func (f *IntSliceFlag) SetValue(slice []int) {
f.Value = newSliceFlagValue(NewIntSlice, slice)
}

func (f *IntSliceFlag) SetDestination(slice []int) {
f.Destination = newSliceFlagValue(NewIntSlice, slice)
}

func (f *IntSliceFlag) GetDestination() []int {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}

func (f *StringSliceFlag) SetValue(slice []string) {
f.Value = newSliceFlagValue(NewStringSlice, slice)
}

func (f *StringSliceFlag) SetDestination(slice []string) {
f.Destination = newSliceFlagValue(NewStringSlice, slice)
}

func (f *StringSliceFlag) GetDestination() []string {
if destination := f.Destination; destination != nil {
return destination.Value()
}
return nil
}
10 changes: 10 additions & 0 deletions sliceflag_pre18.go
@@ -0,0 +1,10 @@
//go:build !go1.18
// +build !go1.18

package cli

import (
"flag"
)

func unwrapFlagValue(v flag.Value) flag.Value { return v }
3 changes: 3 additions & 0 deletions sliceflag_test.go
@@ -1,3 +1,6 @@
//go:build go1.18
// +build go1.18

package cli

import (
Expand Down

0 comments on commit 4f795e3

Please sign in to comment.