8000 Add CLI arg for forced location search by mlange-42 · Pull Request #41 · mlange-42/tom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add CLI arg for forced location search #41

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

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10000
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [[unpublished]](https://github.com/mlange-42/tom/compare/v0.4.0...main)

### Features

- Adds flag `--search`/`-?` to force location search (#40)

## [[v0.4.0]](https://github.com/mlange-42/tom/compare/v0.3.0...v0.4.0)

### Features
Expand Down
13 changes: 7 additions & 6 deletions config/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
)

type CliArgs struct {
Location string
Coords Location `yaml:"-"`
SetDefault bool `yaml:"-"`
Days int
PastDays int
Service Service
Location string
Coords Location `yaml:"-"`
SetDefault bool `yaml:"-"`
ForceSearch bool `yaml:"-"`
Days int
PastDays int
Service Service
}

func LoadCliArgs() (CliArgs, error) {
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func rootCommand() (*cobra.Command, error) {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
forceSearchLoc := false
if len(args) == 0 {
if defaults.Location == "" {
cmd.Help()
Expand All @@ -59,7 +58,7 @@ func rootCommand() (*cobra.Command, error) {
}
} else {
defaults.Location = strings.ToLower(strings.Join(args, " "))
forceSearchLoc = strings.HasSuffix(defaults.Location, "?")
defaults.ForceSearch = strings.HasSuffix(defaults.Location, "?")
defaults.Location = strings.TrimSuffix(defaults.Location, "?")
}

Expand Down Expand Up @@ -100,7 +99,7 @@ func rootCommand() (*cobra.Command, error) {
}

coords, ok := cached[defaults.Location]
if ok && !forceSearchLoc {
if ok && !defaults.ForceSearch {
defaults.Coords = coords
a := app.New(defaults)
if err := a.Run(); err != nil {
Expand All @@ -121,6 +120,7 @@ func rootCommand() (*cobra.Command, error) {
root.Flags().IntVarP(&cli.PastDays, "past-days", "p", 0, "Number of past days to include")
root.Flags().StringVarP(&cli.Service.Name, "service", "s", "OM", "Forecast service:\n"+services)
root.Flags().BoolVarP(&cli.SetDefault, "default", "", false, "Save given location and settings as default")
root.Flags().BoolVarP(&cli.ForceSearch, "search", "?", false, "Force location search instead of previously saved")

root.Flags().SortFlags = false

Expand Down
Loading
0