-
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 #7 from dominikwinter/6-support-for-subcommands-in…
…-cli add support for subcommands
- Loading branch information
Showing
14 changed files
with
108 additions
and
66 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 +1,2 @@ | ||
.DS_Store | ||
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 |
---|---|---|
@@ -1,26 +1,31 @@ | ||
.PHONY: default test build install clean release | ||
|
||
.PHONY: default | ||
default: build | ||
|
||
.PHONY: run | ||
run: | ||
go run cmd/genpno/main.go | ||
go run | ||
|
||
.PHONY: test | ||
test: | ||
go test -v --race -cpu 2 -cover -shuffle on -vet '' ./... | ||
|
||
.PHONY: build | ||
build: | ||
go build -o bin/genpno cmd/genpno/main.go | ||
go build -trimpath -o ./bin/pno | ||
|
||
.PHONY: install | ||
install: | ||
go install bin/genpno | ||
install -b -S -v ./bin/pno ${GOPATH}/bin/. | ||
|
||
.PHONY: clean | ||
clean: | ||
go mod tidy | ||
|
||
.PHONY: release | ||
release: | ||
mkdir -p bin | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/genpno-macos-arm64 cmd/genpno/main.go | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/genpno-linux-amd64 cmd/genpno/main.go | ||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o bin/genpno-linux-386 cmd/genpno/main.go | ||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/genpno-windows-amd64.exe cmd/genpno/main.go | ||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o bin/genpno-windows-386.exe cmd/genpno/main.go | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/pno-macos-arm64 | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/pno-linux-amd64 | ||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o bin/pno-linux-386 | ||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/pno-windows-amd64.exe | ||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o bin/pno-windows-386.exe |
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,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/dominikwinter/pno/internal/gen" | ||
) | ||
|
||
func Run(args []string) { | ||
fs := flag.NewFlagSet("pno gen", flag.ExitOnError) | ||
|
||
helpFlag := fs.Bool("h", false, "Help") | ||
verboseFlag := fs.Bool("v", false, "Verbose") | ||
|
||
dateFlag := fs.String("d", "", "Date (format: yyyymmdd) (default random)") | ||
countryFlag := fs.String("c", "", "Country code (default random)") | ||
genderFlag := fs.String("g", "", "Gender (m/f) (default random)") | ||
formatFlag := fs.String("f", "", `Output forma (default 3): | ||
1. yymmddccgn | ||
2. yymmdd-ccgn | ||
3. yyyymmddccgn | ||
4. yyyymmdd-ccgn`) | ||
|
||
fs.Parse(args) | ||
|
||
if *helpFlag { | ||
fs.Usage() | ||
return | ||
} | ||
|
||
pno, err := gen.GeneratePno(*dateFlag, *countryFlag, *genderFlag, *formatFlag) | ||
|
||
if err != nil { | ||
if *verboseFlag { | ||
panic(err) | ||
} else { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
|
||
fmt.Println(pno) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/dominikwinter/genpno | ||
module github.com/dominikwinter/pno | ||
|
||
go 1.21.6 |
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,4 +1,4 @@ | ||
package generator | ||
package gen | ||
|
||
import ( | ||
"fmt" | ||
|
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,4 +1,4 @@ | ||
package generator | ||
package gen | ||
|
||
import ( | ||
"fmt" | ||
|
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,4 +1,4 @@ | ||
package generator | ||
package gen | ||
|
||
import ( | ||
"fmt" | ||
|
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,4 +1,4 @@ | ||
package generator | ||
package gen | ||
|
||
import "fmt" | ||
|
||
|
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,4 +1,4 @@ | ||
package generator | ||
package gen | ||
|
||
import ( | ||
"fmt" | ||
|
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,4 +1,4 @@ | ||
package generator | ||
package gen | ||
|
||
import "fmt" | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
internal/generator/generate_test.go → internal/gen/generate_test.go
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,4 +1,4 @@ | ||
package generator | ||
package gen | ||
|
||
import ( | ||
"strconv" | ||
|
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,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/dominikwinter/pno/cmd" | ||
) | ||
|
||
func main() { | ||
const usage = `Usage of pno <command> [<args>]: | ||
commands: | ||
gen Generate a personal number | ||
args: | ||
-h Help` | ||
|
||
if len(os.Args) < 2 { | ||
fmt.Fprintln(os.Stderr, usage) | ||
|
||
os.Exit(1) | ||
} | ||
|
||
command, args := os.Args[1], os.Args[2:] | ||
|
||
switch command { | ||
case "gen": | ||
cmd.Run(args) | ||
default: | ||
fmt.Fprintf(os.Stderr, "Unrecognized command %s.\n\n%s\n", command, usage) | ||
os.Exit(1) | ||
} | ||
} |