Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ff for env var configuration #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/muesli/mango v0.2.0
github.com/muesli/roff v0.1.0
github.com/muesli/termenv v0.13.0
github.com/peterbourgon/ff/v3 v3.3.0
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab
golang.org/x/term v0.0.0-20210406210042-72f3dc4e9b72
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0=
github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/peterbourgon/ff/v3 v3.3.0 h1:PaKe7GW8orVFh8Unb5jNHS+JZBwWUMa2se0HM6/BI24=
github.com/peterbourgon/ff/v3 v3.3.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ=
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -44,6 +47,7 @@ golang.org/x/term v0.0.0-20210406210042-72f3dc4e9b72/go.mod h1:bj7SfCRtBDWHUb9sn
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
49 changes: 27 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
wildcard "github.com/IGLOU-EU/go-wildcard"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/muesli/termenv"
"github.com/peterbourgon/ff/v3"
"golang.org/x/term"
)

Expand All @@ -29,27 +30,28 @@ var (
groups = []string{localDevice, networkDevice, fuseDevice, specialDevice, loopsDevice, bindsMount}
allowedValues = strings.Join(groups, ", ")

all = flag.Bool("all", false, "include pseudo, duplicate, inaccessible file systems")
hideDevices = flag.String("hide", "", "hide specific devices, separated with commas:\n"+allowedValues)
hideFs = flag.String("hide-fs", "", "hide specific filesystems, separated with commas")
hideMp = flag.String("hide-mp", "", "hide specific mount points, separated with commas (supports wildcards)")
onlyDevices = flag.String("only", "", "show only specific devices, separated with commas:\n"+allowedValues)
onlyFs = flag.String("only-fs", "", "only specific filesystems, separated with commas")
onlyMp = flag.String("only-mp", "", "only specific mount points, separated with commas (supports wildcards)")

output = flag.String("output", "", "output fields: "+strings.Join(columnIDs(), ", "))
sortBy = flag.String("sort", "mountpoint", "sort output by: "+strings.Join(columnIDs(), ", "))
width = flag.Uint("width", 0, "max output width")
themeOpt = flag.String("theme", defaultThemeName(), "color themes: dark, light, ansi")
styleOpt = flag.String("style", defaultStyleName(), "style: unicode, ascii")

availThreshold = flag.String("avail-threshold", "10G,1G", "specifies the coloring threshold (yellow, red) of the avail column, must be integer with optional SI prefixes")
usageThreshold = flag.String("usage-threshold", "0.5,0.9", "specifies the coloring threshold (yellow, red) of the usage bars as a floating point number from 0 to 1")

inodes = flag.Bool("inodes", false, "list inode information instead of block usage")
jsonOutput = flag.Bool("json", false, "output all devices in JSON format")
warns = flag.Bool("warnings", false, "output all warnings to STDERR")
version = flag.Bool("version", false, "display version")
fs = flag.NewFlagSet("duf", flag.ContinueOnError)
all = fs.Bool("all", false, "include pseudo, duplicate, inaccessible file systems")
hideDevices = fs.String("hide", "", "hide specific devices, separated with commas:\n"+allowedValues)
hideFs = fs.String("hide-fs", "", "hide specific filesystems, separated with commas")
hideMp = fs.String("hide-mp", "", "hide specific mount points, separated with commas (supports wildcards)")
onlyDevices = fs.String("only", "", "show only specific devices, separated with commas:\n"+allowedValues)
onlyFs = fs.String("only-fs", "", "only specific filesystems, separated with commas")
onlyMp = fs.String("only-mp", "", "only specific mount points, separated with commas (supports wildcards)")

output = fs.String("output", "", "output fields: "+strings.Join(columnIDs(), ", "))
sortBy = fs.String("sort", "mountpoint", "sort output by: "+strings.Join(columnIDs(), ", "))
width = fs.Uint("width", 0, "max output width")
themeOpt = fs.String("theme", defaultThemeName(), "color themes: dark, light, ansi")
styleOpt = fs.String("style", defaultStyleName(), "style: unicode, ascii")

availThreshold = fs.String("avail-threshold", "10G,1G", "specifies the coloring threshold (yellow, red) of the avail column, must be integer with optional SI prefixes")
usageThreshold = fs.String("usage-threshold", "0.5,0.9", "specifies the coloring threshold (yellow, red) of the usage bars as a floating point number from 0 to 1")

inodes = fs.Bool("inodes", false, "list inode information instead of block usage")
jsonOutput = fs.Bool("json", false, "output all devices in JSON format")
warns = fs.Bool("warnings", false, "output all warnings to STDERR")
version = fs.Bool("version", false, "display version")
)

// renderJSON encodes the JSON output and prints it.
Expand Down Expand Up @@ -143,7 +145,10 @@ func findInKey(str string, km map[string]struct{}) bool {
}

func main() {
flag.Parse()
if err := ff.Parse(fs, os.Args[1:], ff.WithEnvVarPrefix("DUF")); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}

if *version {
if len(CommitSHA) > 7 {
Expand Down