Skip to content

Commit

Permalink
Upgrade urfave cli to v2 (#77)
Browse files Browse the repository at this point in the history
* Upgrade urfave cli to v2

* Remove deprecated func
  • Loading branch information
zix99 committed Aug 21, 2022
1 parent 29bee6a commit fccfed4
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 228 deletions.
31 changes: 17 additions & 14 deletions cmd/analyze.go
Expand Up @@ -9,7 +9,7 @@ import (
"rare/pkg/multiterm"
"strconv"

"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func humanf(arg interface{}) string {
Expand Down Expand Up @@ -78,26 +78,29 @@ func analyzeFunction(c *cli.Context) error {

func analyzeCommand() *cli.Command {
return helpers.AdaptCommandForExtractor(cli.Command{
Name: "analyze",
ShortName: "a",
Usage: "Numerical analysis on a set of filtered data",
Name: "analyze",
Aliases: []string{"a"},
Usage: "Numerical analysis on a set of filtered data",
Description: `Treat every extracted expression as a numerical input, and run analysis
on that input. Will extract mean, median, mode, min, max. If specifying --extra
will also extract std deviation, and quantiles`,
Action: analyzeFunction,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "extra,x",
Usage: "Displays extra analysis on the data (Requires more memory and cpu)",
&cli.BoolFlag{
Name: "extra",
Aliases: []string{"x"},
Usage: "Displays extra analysis on the data (Requires more memory and cpu)",
},
cli.BoolFlag{
Name: "reverse,r",
Usage: "Reverses the numerical series when ordered-analysis takes place (eg Quantile)",
&cli.BoolFlag{
Name: "reverse",
Aliases: []string{"r"},
Usage: "Reverses the numerical series when ordered-analysis takes place (eg Quantile)",
},
cli.StringSliceFlag{
Name: "quantile,q",
Usage: "Adds a quantile to the output set. Requires --extra",
Value: &cli.StringSlice{"90", "99", "99.9"},
&cli.StringSliceFlag{
Name: "quantile",
Aliases: []string{"q"},
Usage: "Adds a quantile to the output set. Requires --extra",
Value: cli.NewStringSlice("90", "99", "99.9"),
},
},
})
Expand Down
18 changes: 9 additions & 9 deletions cmd/bargraph.go
Expand Up @@ -6,7 +6,7 @@ import (
"rare/pkg/multiterm"
"rare/pkg/multiterm/termrenderers"

"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

/*
Expand Down Expand Up @@ -47,21 +47,21 @@ func bargraphFunction(c *cli.Context) error {

func bargraphCommand() *cli.Command {
return helpers.AdaptCommandForExtractor(cli.Command{
Name: "bargraph",
Aliases: []string{"bar", "bars"},
ShortName: "b",
Usage: "Create a bargraph of the given 1 or 2 dimension data",
Name: "bargraph",
Aliases: []string{"bars", "bar", "b"},
Usage: "Create a bargraph of the given 1 or 2 dimension data",
Description: `Creates a bargraph of one or two dimensional data. Unlike histogram
the bargraph can collapse and stack data in different formats. The key data format
is {$ a b [c]}, where a is the base-key, b is the optional sub-key, and c is the increment
(defaults to 1)`,
Action: bargraphFunction,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "stacked,s",
Usage: "Display bargraph as stacked",
&cli.BoolFlag{
Name: "stacked",
Aliases: []string{"s"},
Usage: "Display bargraph as stacked",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "reverse",
Usage: "Reverses the display sort-order",
},
Expand Down
20 changes: 10 additions & 10 deletions cmd/commands.go
@@ -1,17 +1,17 @@
package cmd

import "github.com/urfave/cli"
import "github.com/urfave/cli/v2"

var commands []cli.Command = []cli.Command{
*filterCommand(),
*histogramCommand(),
*heatmapCommand(),
*bargraphCommand(),
*analyzeCommand(),
*tabulateCommand(),
*docsCommand(),
var commands []*cli.Command = []*cli.Command{
filterCommand(),
histogramCommand(),
heatmapCommand(),
bargraphCommand(),
analyzeCommand(),
tabulateCommand(),
docsCommand(),
}

func GetSupportedCommands() []cli.Command {
func GetSupportedCommands() []*cli.Command {
return commands
}
6 changes: 3 additions & 3 deletions cmd/commands_test.go
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func TestCommandGetter(t *testing.T) {
Expand All @@ -29,8 +29,8 @@ func testCommand(command *cli.Command, cmd string) error {
app := cli.NewApp()

command.Name = "_testcommand"
app.Commands = []cli.Command{
*command,
app.Commands = []*cli.Command{
command,
}
app.ExitErrHandler = func(context *cli.Context, err error) {
// disabled
Expand Down
11 changes: 6 additions & 5 deletions cmd/docs.go
Expand Up @@ -12,7 +12,7 @@ import (
"rare/pkg/markdowncli"
"strings"

"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func docsFunction(c *cli.Context) error {
Expand All @@ -27,7 +27,7 @@ func docsFunction(c *cli.Context) error {
io.Copy(os.Stdout, &buf)
}
} else {
return cli.NewExitError(fmt.Sprintf("No such doc '%s'", docname), helpers.ExitCodeInvalidUsage)
return cli.Exit(fmt.Sprintf("No such doc '%s'", docname), helpers.ExitCodeInvalidUsage)
}

return nil
Expand Down Expand Up @@ -71,9 +71,10 @@ func docsCommand() *cli.Command {
ArgsUsage: "[doc]",
Action: docsFunction,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "no-pager,n",
Usage: "Don't use pager to view documentation",
&cli.BoolFlag{
Name: "no-pager",
Aliases: []string{"n"},
Usage: "Don't use pager to view documentation",
},
},
}
Expand Down
20 changes: 11 additions & 9 deletions cmd/filter.go
Expand Up @@ -7,7 +7,7 @@ import (
"rare/cmd/helpers"
"rare/pkg/color"

"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func filterFunction(c *cli.Context) error {
Expand Down Expand Up @@ -68,16 +68,18 @@ func filterCommand() *cli.Command {
Usage: "Filter incoming results with search criteria, and output raw matches",
Description: `Filters incoming results by a regex, and output the match of a single line
or an extracted expression.`,
ShortName: "f",
Action: filterFunction,
Aliases: []string{"f"},
Action: filterFunction,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "line,l",
Usage: "Output source file and line number",
&cli.BoolFlag{
Name: "line",
Aliases: []string{"l"},
Usage: "Output source file and line number",
},
cli.Int64Flag{
Name: "n,num",
Usage: "Print the first NUM of lines seen (Not necessarily in-order)",
&cli.Int64Flag{
Name: "num",
Aliases: []string{"n"},
Usage: "Print the first NUM of lines seen (Not necessarily in-order)",
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/filter_test.go
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func TestFilter(t *testing.T) {
Expand Down
83 changes: 45 additions & 38 deletions cmd/fuzzy.go
@@ -1,4 +1,4 @@
// +build experimental
//go:build experimental

package cmd

Expand All @@ -11,7 +11,7 @@ import (
"rare/pkg/multiterm"
"rare/pkg/multiterm/termrenderers"

"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func fuzzyFunction(c *cli.Context) error {
Expand Down Expand Up @@ -64,69 +64,76 @@ func fuzzyFunction(c *cli.Context) error {

func fuzzyCommand() *cli.Command {
return helpers.AdaptCommandForExtractor(cli.Command{
Name: "fuzzy",
ShortName: "z",
Aliases: []string{"fuz"},
Usage: "(EXPERIMENTAL) Look for similar matches by using a fuzzy search algorithm",
Name: "fuzzy",
Aliases: []string{"fuz", "z"},
Usage: "(EXPERIMENTAL) Look for similar matches by using a fuzzy search algorithm",
Description: `Generates a live-updating histogram of the input data, looking
for a relative distance between various results. This is useful to find
similar log messages that may have slight differences to them (eg ids)
and aggregating and search for these messages`,
Action: fuzzyFunction,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "all,a",
Usage: "After summarization is complete, print all histogram buckets",
&cli.BoolFlag{
Name: "all",
Aliases: []string{"a"},
Usage: "After summarization is complete, print all histogram buckets",
},
cli.BoolFlag{
Name: "bars,b",
Usage: "Display bars as part of histogram",
&cli.BoolFlag{
Name: "bars",
Aliases: []string{"b"},
Usage: "Display bars as part of histogram",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "percentage",
Usage: "Display percentage of total next to the value",
},
cli.BoolFlag{
Name: "extra,x",
Usage: "Alias for -b --percentage",
&cli.BoolFlag{
Name: "extra",
Aliases: []string{"x"},
Usage: "Alias for -b --percentage",
},
cli.IntFlag{
Name: "num,n",
Usage: "Number of elements to display",
Value: 5,
&cli.IntFlag{
Name: "num",
Aliases: []string{"n"},
Usage: "Number of elements to display",
Value: 5,
},
cli.Int64Flag{
&cli.Int64Flag{
Name: "atleast",
Usage: "Only show results if there are at least this many samples",
Value: 0,
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "reverse",
Usage: "Reverses the display sort-order",
},
cli.BoolFlag{
Name: "sortkey,sk",
Usage: "Sort by key, rather than value",
&cli.BoolFlag{
Name: "sortkey",
Aliases: []string{"sk"},
Usage: "Sort by key, rather than value",
},
cli.Float64Flag{
Name: "similarity,s",
Usage: "The expression string has to be at least this percent similar to qualify as a fuzzy match",
Value: 0.75,
&cli.Float64Flag{
Name: "similarity",
Aliases: []string{"s"},
Usage: "The expression string has to be at least this percent similar to qualify as a fuzzy match",
Value: 0.75,
},
cli.Int64Flag{
Name: "similarity-offset,so",
Usage: "The max offset to examine in the string to look for a similarity",
Value: 10,
&cli.Int64Flag{
Name: "similarity-offset",
Aliases: []string{"so"},
Usage: "The max offset to examine in the string to look for a similarity",
Value: 10,
},
cli.Int64Flag{
Name: "similarity-size,ss",
Usage: "The maximum size a similarity table can grow to. Keeps the top most-likely keys at all times",
Value: 100,
&cli.Int64Flag{
Name: "similarity-size",
Aliases: []string{"ss"},
Usage: "The maximum size a similarity table can grow to. Keeps the top most-likely keys at all times",
Value: 100,
},
},
})
}

func init() {
commands = append(commands, *fuzzyCommand())
commands = append(commands, fuzzyCommand())
}

0 comments on commit fccfed4

Please sign in to comment.