Skip to content

Commit

Permalink
feat: add --version flag
Browse files Browse the repository at this point in the history
resolves #17
  • Loading branch information
BrunnerLivio committed Oct 5, 2023
1 parent c593050 commit 4562d53
Show file tree
Hide file tree
Showing 7 changed files with 636 additions and 13 deletions.
27 changes: 27 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
const plugins = [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"semantic-release-replace-plugin",
{
"replacements": [
{
"files": ["version.go"],
"from": "const VERSION = \".*\"",
"to": "const VERSION = \"${nextRelease.version}\"",
"results": [
{
"file": "version.go",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}
],
"countMatches": true
}
]
}
],
[
"@semantic-release/git",
{
"assets": ["version.go"]
}
],
[
"@semantic-release/exec",
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ts -L sleep sleep 30
| `--host` | `TSP_WEB_HOSTNAME` | The hostname to run TSP-Web on | `192.168.0.20` | `localhost` |
| `--log-level` | `TSP_WEB_LOG_LEVEL` | The log level can be `'debug' or 'info' or 'warn'` | `warn` | `info` |
| `--no-color` | - | Whether the logs should be displayed without colors | - | `false` |
| `--version` | - | Prints the version | - | |

### Configuration

Expand Down
1 change: 1 addition & 0 deletions internal/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ type TspWebArgs struct {
LogLevel string
NoColor bool
Host string
Version bool
}
21 changes: 13 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ func parseArgs() (args.TspWebArgs, error) {
logLevel := flag.String("log-level", utils.Getenv("TSP_WEB_LOG_LEVEL", "info"), "The log level for tsp-web")
noColor := flag.Bool("no-color", false, "Disable colorized output")
host := flag.String("host", utils.Getenv("TSP_WEB_HOSTNAME", "localhost"), "The host for tsp-web")
version := flag.Bool("version", false, "Print the version and exit")

flag.Parse()

if *portArg > maxPort {
return args.TspWebArgs{}, fmt.Errorf("invalid value \"%d\" for flag -port: parse error", *portArg)
log.Errorf("invalid value \"%d\" for flag -port: value out of range", *portArg)
flag.Usage()
os.Exit(1)
}

Port := uint16(*portArg)
Expand All @@ -43,7 +46,9 @@ func parseArgs() (args.TspWebArgs, error) {
Port: Port,
LogLevel: *logLevel,
NoColor: *noColor,
Host: *host}, nil
Host: *host,
Version: *version,
}, nil
}

func setLogLevel(logLevel string) {
Expand All @@ -63,18 +68,18 @@ func main() {
api.Static = static

args, err := parseArgs()

if args.Version {
fmt.Println(VERSION)

Check failure on line 73 in main.go

View workflow job for this annotation

GitHub Actions / build (Linux amd64, linux, amd64, .bin/tsp-web_linux_amd64)

undefined: VERSION
os.Exit(0)
}

setLogLevel(args.LogLevel)
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
DisableColors: args.NoColor,
})

if err != nil {
log.Error(err)
flag.Usage()
os.Exit(1)
}

userconf.Load(args)
go userconf.StartWatcher(args)
err = api.Run(args)
Expand Down
Loading

0 comments on commit 4562d53

Please sign in to comment.