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

Added autocomplete function for time zones #2

Merged
merged 5 commits into from
Jan 10, 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
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# timeBuddy

CLI based version of World Time Buddy
CLI based version of [World Time Buddy](https://www.worldtimebuddy.com/)

## Description

TimeBuddy is a CLI tool, implemented in Go, that mimics the functionality of World Time Buddy. It accepts a list of timezone and displays the current time in each of these timezones in a tabular format. The program is aware of daylight savings time and adjusts the time for each timezone accordingly. A specific date can also be provided to view the time in each timezone for that date.
TimeBuddy is a CLI tool, implemented in Go, that mimics the functionality of World Time Buddy. It accepts a list of timezones and displays the current time for each in a tabular format. You can use `timeBuddy list` to view a list of all available timezones. Alternatively, you can setup the shell autocompletion script(`timeBuddy completion --help`) for your preferred shell and use tab completion to select the timezones you are interested in.

The program is aware of daylight savings time and adjusts the time for each timezone accordingly. A specific date can also be provided to view the time in each timezone for that date.

The last used timezones, color, and time format preferences are saved in a YAML formatted configuration file. This feature ensures that you need to
specify your preferred time zones only once. The order in which you specify the time zones is retained and reflected in the table output.

- Windows: `$HOME/AppData/Roaming/.timeBuddy.yaml`
- Linux/macOS: `~/.config/.timeBuddy.yaml`

If the configuration file does not exist, it will be created. The configuration file follows the format:
If the configuration file does not exist, it will be created. The configuration file has the following format:

```yaml
color: true
Expand All @@ -35,7 +37,7 @@ twelve-hour: false
## Installation

1. Download the binary for your preferred platform from the [releases](https://github.com/JakeTRogers/timeBuddy/releases) page
2. Extract the archive. It can contains the markdown generated documentation and the binary
2. Extract the archive. It contains this readme, a copy of the Apache 2.0 license, and the timeBuddy binary.
3. Copy the binary to a directory in your `$PATH`. i.e. `/usr/local/bin`

## Usage
Expand All @@ -62,3 +64,16 @@ Flags:

Use "timeBuddy [command] --help" for more information about a command.
```

## Examples

```bash
# Display the current time in New York, Vilnius, and Sydney
timeBuddy -z America/New_York -z Europe/Vilnius -z Australia/Sydney

# Display the current time in 12-hour format and in color using the last used timezones
timeBuddy -t -c

# Display the time table of your last used timezones, color, and time format for a specific date
timeBuddy -d 2024-06-06
```
10 changes: 8 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strings"
"time"
_ "time/tzdata"
"timeBuddy/logger"

"github.com/JakeTRogers/timeBuddy/logger"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -342,7 +342,7 @@ Examples:

Learn More:
To submit feature requests, bugs, or to check for new versions, visit https://github.com/JakeTRogers/timeBuddy`,
Version: "v1.0.1",
Version: "v1.1.1",
Args: func(cmd *cobra.Command, args []string) error {
// if the --date flag was provided, validate it
if cmd.Flags().Changed("date") {
Expand Down Expand Up @@ -417,4 +417,10 @@ func init() {
rootCmd.PersistentFlags().CountP("verbose", "v", "``increase logging verbosity, 1=warn, 2=info, 3=debug, 4=trace")
rootCmd.Flags().BoolP("exclude-local", "x", false, "disable default behavior of including local timezone in output")
rootCmd.Flags().StringArrayVarP(&timezones, "timezone", "z", []string{}, "``timezone to use for time conversion. Accepts timezone name, like America/New_York. Can be used multiple times.")
err := rootCmd.RegisterFlagCompletionFunc("timezone", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return timezonesAll, cobra.ShellCompDirectiveDefault
})
if err != nil {
l.Error().Err(err).Send()
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module timeBuddy
module github.com/JakeTRogers/timeBuddy

go 1.21

Expand Down Expand Up @@ -29,7 +29,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright © 2024 Jake Rogers <[email protected]>
*/
package main

import "timeBuddy/cmd"
import "github.com/JakeTRogers/timeBuddy/cmd"

func main() {
cmd.Execute()
Expand Down
Loading