Skip to content

Commit

Permalink
feat: add --line-number,-l flag
Browse files Browse the repository at this point in the history
  • Loading branch information
iret-kawashima committed Dec 5, 2023
1 parent e48c680 commit 45be252
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
34 changes: 30 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type destination struct {
output string
skip cli.IntSlice
metadata bool
lineNum bool
glob string
}

Expand All @@ -90,6 +91,7 @@ type flag struct {
output *cli.StringFlag
skip *cli.IntSliceFlag
metadata *cli.BoolFlag
lineNum *cli.BoolFlag
glob *cli.StringFlag
}

Expand Down Expand Up @@ -144,6 +146,12 @@ func newApp() *app {
Usage: "enable metadata output",
Destination: &a.destination.metadata,
}
a.flag.lineNum = &cli.BoolFlag{
Name: "line-number",
Aliases: []string{"l"},
Usage: "set line number at the beginning of the line",
Destination: &a.destination.lineNum,
}
a.flag.glob = &cli.StringFlag{
Name: "glob-pattern",
Aliases: []string{"G"},
Expand All @@ -159,6 +167,7 @@ func newApp() *app {
a.flag.output,
a.flag.skip,
a.flag.metadata,
a.flag.lineNum,
a.flag.glob,
}
a.cli = &cli.App{
Expand Down Expand Up @@ -357,16 +366,33 @@ func (a *app) out(c *cli.Context, p parser.Parser) error {
func (a *app) dispatch(c *cli.Context, p parser.Parser) (result *parser.Result, results []*parser.Result, err error) {
switch {
case c.IsSet(a.flag.input.Name):
result, err = p.ParseString(a.destination.input, a.destination.skip.Value())
result, err = p.ParseString(
a.destination.input,
a.destination.skip.Value(),
a.destination.lineNum,
)
return result, nil, err
case c.IsSet(a.flag.file.Name):
result, err = p.ParseFile(a.destination.file, a.destination.skip.Value())
result, err = p.ParseFile(
a.destination.file,
a.destination.skip.Value(),
a.destination.lineNum,
)
return result, nil, err
case c.IsSet(a.flag.gzip.Name):
result, err = p.ParseGzip(a.destination.gzip, a.destination.skip.Value())
result, err = p.ParseGzip(
a.destination.gzip,
a.destination.skip.Value(),
a.destination.lineNum,
)
return result, nil, err
case c.IsSet(a.flag.zip.Name):
results, err = p.ParseZipEntries(a.destination.zip, a.destination.skip.Value(), a.destination.glob)
results, err = p.ParseZipEntries(
a.destination.zip,
a.destination.skip.Value(),
a.destination.lineNum,
a.destination.glob,
)
return nil, results, err
default:
return nil, nil, fmt.Errorf(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/nekrassov01/alpen
go 1.21

require (
github.com/nekrassov01/access-log-parser v0.0.11
github.com/nekrassov01/access-log-parser v0.0.13
github.com/urfave/cli/v2 v2.25.7
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/nekrassov01/access-log-parser v0.0.11 h1:nhlRt9GqYfwi1YQ/UaiH5w0LRWWeYqVQBePjmhJYxFo=
github.com/nekrassov01/access-log-parser v0.0.11/go.mod h1:JTLHNxuWs0eOSFPIcQ8YClAYIwVtkvXGYkQALEYSvlg=
github.com/nekrassov01/access-log-parser v0.0.13 h1:Vw9e9nCss1tV3Koq+dNVO4NcSseIJkm54iMrUfiOxYA=
github.com/nekrassov01/access-log-parser v0.0.13/go.mod h1:JTLHNxuWs0eOSFPIcQ8YClAYIwVtkvXGYkQALEYSvlg=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
Expand Down

0 comments on commit 45be252

Please sign in to comment.