-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also: - refactor the root command usage - create global variables for config, cache and client This doesn't feel correct, but I'll deal with changing that later
- Loading branch information
Showing
5 changed files
with
118 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/nobe4/gh-not/internal/cmd" | ||
) | ||
|
||
func main() { | ||
cmd.Execute() | ||
if err := cmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List notifications", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
notifications, err := client.Notifications() | ||
if err != nil { | ||
slog.Error("Failed to list notifications", "err", err) | ||
return err | ||
} | ||
|
||
fmt.Println(notifications.ToString()) | ||
return nil | ||
}, | ||
} | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cmd | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"github.com/nobe4/gh-not/internal/actors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
noop bool | ||
|
||
syncCmd = &cobra.Command{ | ||
Use: "sync", | ||
Short: "Sync notifications based on your config", | ||
Long: ` | ||
'gh-not sync' applies the ruleset on all the notifications in the cache. | ||
Use this command when you want to make sure that your notification list is up to | ||
date with your ruleset. | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
notifications, err := client.Notifications() | ||
if err != nil { | ||
slog.Error("Failed to list notifications", "err", err) | ||
return err | ||
} | ||
|
||
notifications, err = config.Apply(notifications, actors.Map(client), noop) | ||
if err != nil { | ||
slog.Error("Failed to applying rules", "err", err) | ||
return err | ||
} | ||
|
||
if err := cache.Write(notifications); err != nil { | ||
slog.Error("Failed to write the cache", "err", err) | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
syncCmd.Flags().BoolVarP(&noop, "no-op", "n", false, "Doesn't execute any action") | ||
} |