mirror of
https://github.com/onyx-and-iris/gignore.git
synced 2025-04-07 22:23:52 +01:00
-loglevel now string flag
upd README, CHANGELOG
This commit is contained in:
parent
38b0611e4e
commit
6aac14b9ed
@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
# [0.3.0] - 2024-14-03
|
||||
# [0.4.0] - 2025-04-05
|
||||
|
||||
### Changed
|
||||
|
||||
- `-loglevel` flag is now of type string. It accepts any one of trace, debug, info, warn, error, fatal or panic.
|
||||
- It defaults to warn.
|
||||
|
||||
# [0.3.0] - 2025-14-03
|
||||
|
||||
### Added
|
||||
|
||||
|
22
README.md
22
README.md
@ -56,6 +56,28 @@ You may set an environment variable `GIGNORE_TEMPLATE_DIR` to avoid passing the
|
||||
|
||||
If a template is requested but not found in the custom directory then the gitignoreio registry will act as a fallback.
|
||||
|
||||
## Logging
|
||||
|
||||
The `-loglevel` flag allows you to control the verbosity of the application's logging output.
|
||||
|
||||
Acceptable values for this flag are:
|
||||
|
||||
- `trace`
|
||||
- `debug`
|
||||
- `info`
|
||||
- `warn`
|
||||
- `error`
|
||||
- `fatal`
|
||||
- `panic`
|
||||
|
||||
For example, to set the log level to `debug`, you can use:
|
||||
|
||||
```
|
||||
vbantxt -s=streamname -log-level=debug "bus[0].eq.on=1 bus[1].gain=-12.8"
|
||||
```
|
||||
|
||||
The default log level is `warn` if the flag is not specified.
|
||||
|
||||
## Special Thanks
|
||||
|
||||
[gitignore.io][gitignoreio] For providing such a useful .gitignore service
|
||||
|
@ -5,12 +5,17 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"slices"
|
||||
"os"
|
||||
|
||||
"github.com/onyx-and-iris/gignore"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func exit(err error) {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = func() {
|
||||
w := flag.CommandLine.Output()
|
||||
@ -30,7 +35,7 @@ func main() {
|
||||
var (
|
||||
list bool
|
||||
templateDir string
|
||||
loglevel int
|
||||
loglevel string
|
||||
)
|
||||
|
||||
flag.BoolVar(&list, "list", false, "list available templates")
|
||||
@ -41,19 +46,22 @@ func main() {
|
||||
getEnv("GIGNORE_TEMPLATE_DIR", "gitignoreio"),
|
||||
"directory containing .gitignore templates",
|
||||
)
|
||||
flag.IntVar(&loglevel, "loglevel", int(log.WarnLevel), "log level")
|
||||
flag.IntVar(&loglevel, "l", int(log.WarnLevel), "log level (shorthand)")
|
||||
flag.StringVar(&loglevel, "loglevel", "warn", "log level")
|
||||
flag.StringVar(&loglevel, "l", "warn", "log level (shorthand)")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if slices.Contains(log.AllLevels, log.Level(loglevel)) {
|
||||
log.SetLevel(log.Level(loglevel))
|
||||
level, err := log.ParseLevel(loglevel)
|
||||
if err != nil {
|
||||
exit(fmt.Errorf("invalid log level: %s", loglevel))
|
||||
}
|
||||
log.SetLevel(level)
|
||||
|
||||
client := gignore.New(gignore.WithTemplateDirectory(templateDir))
|
||||
|
||||
if list {
|
||||
if err := listTemplates(client); err != nil {
|
||||
log.Fatalf("failed to list templates: %v", err)
|
||||
exit(fmt.Errorf("failed to list templates: %v", err))
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -67,7 +75,7 @@ func main() {
|
||||
for _, arg := range args {
|
||||
err := client.Create(arg)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create .gitignore file: %v", err)
|
||||
exit(fmt.Errorf("failed to create .gitignore file: %v", err))
|
||||
}
|
||||
fmt.Printf("√ created %s .gitignore file\n", arg)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user