Skip to content

Commit

Permalink
fix: default package name (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmzane committed Jun 8, 2024
1 parent 6dd67f4 commit 2780299
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ logger.Alert("msg", "key", "value")
Additionally, there are options to choose the API style of the arguments (`...any` or `...slog.Attr`) and to add/remove `context.Context` as the first parameter.
This allows you to adjust the logging API to your own code style without sacrificing convenience.

> [!TIP]
> [!tip]
> Various API rules for `log/slog` can be enforced by the [`sloglint`][1] linter. Give it a try too!
## 🚀 Features
Expand Down Expand Up @@ -166,17 +166,17 @@ slog.New(logger.Handler())
Usage: sloggen [flags]

Flags:
-config <path> read config from the file instead of flags
-dir <path> change the working directory before generating files
-pkg <name> the name for the generated package (default: slogx)
-i <import> add import
-l <name:severity> add level
-c <key> add constant
-a <key:type> add attribute
-logger generate a custom Logger type
-api <any|attr> the API style for the Logger's methods (default: any)
-ctx add context.Context to the Logger's methods
-h, -help print this message and quit
-config <path> read config from the file instead of flags
-dir <path> change the working directory before generating files
-pkg <name> the name for the generated package (default: slogx)
-i <import> add import
-l <name:severity> add level
-c <key> add constant
-a <key:type> add attribute
-logger generate a custom Logger type
-api <any|attr> the API style for the Logger's methods (default: any)
-ctx add context.Context to the Logger's methods
-h, -help print this message and quit
```

For the description of the config file fields, see [`.slog.example.yml`](.slog.example.yml).
Expand Down
27 changes: 15 additions & 12 deletions sloggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ type (
)

func (c *config) prepare() {
if c.Pkg == "" {
c.Pkg = "slogx"
}
if len(c.Levels) > 0 {
c.Imports = append(c.Imports, "log/slog", "fmt", "strings")
}
Expand Down Expand Up @@ -97,22 +100,22 @@ func readFlags(args []string) (*config, error) {
fmt.Println(`Usage: sloggen [flags]
Flags:
-config <path> read config from the file instead of flags
-dir <path> change the working directory before generating files
-pkg <name> the name for the generated package (default: slogx)
-i <import> add import
-l <name:severity> add level
-c <key> add constant
-a <key:type> add attribute
-logger generate a custom Logger type
-api <any|attr> the API style for the Logger's methods (default: any)
-ctx add context.Context to the Logger's methods
-h, -help print this message and quit`)
-config <path> read config from the file instead of flags
-dir <path> change the working directory before generating files
-pkg <name> the name for the generated package (default: slogx)
-i <import> add import
-l <name:severity> add level
-c <key> add constant
-a <key:type> add attribute
-logger generate a custom Logger type
-api <any|attr> the API style for the Logger's methods (default: any)
-ctx add context.Context to the Logger's methods
-h, -help print this message and quit`)
}

fs.StringVar(&cfg.path, "config", "", "")
fs.StringVar(&cfg.dir, "dir", "", "")
fs.StringVar(&cfg.Pkg, "pkg", "slogx", "")
fs.StringVar(&cfg.Pkg, "pkg", "", "")

fs.Func("i", "", func(s string) error {
cfg.Imports = append(cfg.Imports, s)
Expand Down

0 comments on commit 2780299

Please sign in to comment.