-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from winebarrel/add_crongrep
Add crongrep
- Loading branch information
Showing
5 changed files
with
169 additions
and
0 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 |
---|---|---|
|
@@ -23,6 +23,13 @@ builds: | |
- -X main.version={{.Version}} | ||
env: | ||
- CGO_ENABLED=0 | ||
- id: crongrep | ||
binary: crongrep | ||
main: ./cmd/crongrep | ||
ldflags: | ||
- -X main.version={{.Version}} | ||
env: | ||
- CGO_ENABLED=0 | ||
checksum: | ||
name_template: "checksums.txt" | ||
archives: | ||
|
@@ -35,6 +42,9 @@ archives: | |
- id: cronviz | ||
builds: [cronviz] | ||
name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
- id: crongrep | ||
builds: [crongrep] | ||
name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
brews: | ||
- name: cronplan | ||
ids: [cronplan] | ||
|
@@ -66,6 +76,16 @@ brews: | |
license: MIT | ||
install: | | ||
bin.install 'cronviz' | ||
- name: crongrep | ||
ids: [crongrep] | ||
tap: | ||
owner: winebarrel | ||
name: homebrew-cronplan | ||
homepage: https://github.com/winebarrel/cronplan | ||
description: crongrep is a tool to grep with cron expression. | ||
license: MIT | ||
install: | | ||
bin.install 'crongrep' | ||
nfpms: | ||
- id: cronplan-nfpms | ||
builds: [cronplan] | ||
|
@@ -100,3 +120,14 @@ nfpms: | |
- deb | ||
- rpm | ||
bindir: /usr/bin | ||
- id: crongrep-nfpms | ||
builds: [crongrep] | ||
file_name_template: "{{ .Binary }}_{{ .Version }}_{{ .Arch }}" | ||
homepage: https://github.com/winebarrel/cronplan | ||
maintainer: Genki Sugawara <[email protected]> | ||
description: crongrep is a tool to visualize cron schedule. | ||
license: MIT | ||
formats: | ||
- deb | ||
- rpm | ||
bindir: /usr/bin |
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 |
---|---|---|
|
@@ -4,6 +4,12 @@ | |
|
||
N/A | ||
|
||
## [1.10.1] - 2023-10-01 | ||
|
||
### Added | ||
|
||
* Add crongrep CLI. | ||
|
||
## [1.10.0] - 2023-10-01 | ||
|
||
### Added | ||
|
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,64 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var ( | ||
version string | ||
) | ||
|
||
type flags struct { | ||
expr string | ||
} | ||
|
||
func init() { | ||
cmdLine := flag.NewFlagSet(filepath.Base(os.Args[0]), flag.ExitOnError) | ||
|
||
cmdLine.Usage = func() { | ||
fmt.Fprintf(cmdLine.Output(), "Usage: %s [OPTION] CRON_EXPR\n", cmdLine.Name()) | ||
cmdLine.PrintDefaults() | ||
} | ||
|
||
flag.CommandLine = cmdLine | ||
} | ||
|
||
func parseFlags() *flags { | ||
flags := &flags{} | ||
showVersion := flag.Bool("version", false, "print version and exit") | ||
flag.Parse() | ||
|
||
if *showVersion { | ||
printVersionAndExit() | ||
} | ||
|
||
args := flag.Args() | ||
|
||
if len(args) != 1 { | ||
printUsageAndExit() | ||
} | ||
|
||
flags.expr = strings.TrimSpace(args[0]) | ||
|
||
return flags | ||
} | ||
|
||
func printVersionAndExit() { | ||
v := version | ||
|
||
if v == "" { | ||
v = "<nil>" | ||
} | ||
|
||
fmt.Fprintln(flag.CommandLine.Output(), v) | ||
os.Exit(0) | ||
} | ||
|
||
func printUsageAndExit() { | ||
flag.CommandLine.Usage() | ||
os.Exit(0) | ||
} |
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,39 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/araddon/dateparse" | ||
"github.com/winebarrel/cronplan" | ||
) | ||
|
||
func init() { | ||
log.SetFlags(0) | ||
} | ||
|
||
func main() { | ||
flags := parseFlags() | ||
cron, err := cronplan.Parse(flags.expr) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
scanner := bufio.NewScanner(os.Stdin) | ||
|
||
for scanner.Scan() { | ||
line := scanner.Text() | ||
t, err := dateparse.ParseAny(line) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if cron.Match(t) { | ||
fmt.Println(line) | ||
} | ||
} | ||
} |