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

Feat:(issue_1958) Add support for multiple layouts to TimestampFlag #1959

Merged
merged 19 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,7 @@ func TestSetupInitializesOnlyNilWriters(t *testing.T) {
}

func TestFlagAction(t *testing.T) {
now := time.Now().UTC().Truncate(time.Minute)
testCases := []struct {
name string
args []string
Expand Down Expand Up @@ -2578,8 +2579,8 @@ func TestFlagAction(t *testing.T) {
},
{
name: "flag_timestamp",
args: []string{"app", "--f_timestamp", "2022-05-01 02:26:20"},
exp: "2022-05-01T02:26:20Z ",
args: []string{"app", "--f_timestamp", now.Format(time.DateTime)},
exp: now.UTC().Format(time.RFC3339) + " ",
},
{
name: "flag_timestamp_error",
Expand Down Expand Up @@ -2738,12 +2739,14 @@ func TestFlagAction(t *testing.T) {
&TimestampFlag{
Name: "f_timestamp",
Config: TimestampConfig{
Timezone: time.UTC,
AvailableLayouts: []string{time.DateTime},
},
Action: func(_ context.Context, cmd *Command, v time.Time) error {
if v.IsZero() {
return fmt.Errorf("zero timestamp")
}

_, err := cmd.Root().Writer.Write([]byte(v.Format(time.RFC3339) + " "))
return err
},
Expand Down
4 changes: 2 additions & 2 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,8 @@ type SuggestFlagFunc func(flags []Flag, provided string, hideHelp bool) string
type TimestampArg = ArgumentBase[time.Time, TimestampConfig, timestampValue]

type TimestampConfig struct {
Timezone *time.Location
Layout string
Timezone *time.Location
AvailableLayouts []string
}
TimestampConfig defines the config for timestamp flags

Expand Down
Loading
Loading