Skip to content

Commit

Permalink
default output acts like fmt.Println, goreleaser project name
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson committed May 21, 2020
1 parent 214f17f commit d6eb6a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
4 changes: 1 addition & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
before:
hooks:
- go mod tidy
project_name: goodhosts
builds:
- env:
- GO111MODULE=on
Expand Down
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@ architecture. Unzip and run in place, put in your system path (linux: `/usr/loca
For full usage directions simply call `goodhosts -h`

```shell
$ ./goodhosts -h
NAME:
goodhosts - manage your hosts file goodly

USAGE:
goodhosts [global options] command [command options] [arguments...]

COMMANDS:
check, c Check if ip or host exists
list, ls List all entries in the hostsfile
add, a Add an entry to the hostsfile
remove, rm, r Remove ip or host(s) if exists
debug, d Show debug table for hosts file
backup Backup hosts file
restore Restore hosts file from backup
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--custom value override the default hosts file
--debug, -d Turn on verbose debug logging (default: false)
--quiet, -q Turn on off all logging (default: false)
--help, -h show help (default: false)
$ goodhosts --help
NAME:
goodhosts - manage your hosts file goodly

USAGE:
goodhosts [global options] command [command options] [arguments...]

COMMANDS:
check, c Check if ip or host exists
list, ls List all entries in the hostsfile
add, a Add an entry to the hostsfile
remove, rm, r Remove ip or host(s) if exists
debug, d Show debug table for hosts file
backup Backup hosts file
restore Restore hosts file from backup
edit, e Open hosts file in an editor, default vim
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--file value, -f value override the default hosts: /etc/hosts
--debug, -d Turn on verbose debug logging (default: false)
--quiet, -q Turn on off all logging (default: false)
--help, -h show help (default: false)

```
Each sub-command can be called with a `-h` option to see detailed help information.
Expand Down
4 changes: 2 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func list(c *cli.Context) error {
}
}

lineOutput := fmt.Sprintf("%s", line.Raw)
lineOutput := fmt.Sprintf("%s\n", line.Raw)
if line.IsMalformed() {
lineOutput = fmt.Sprintf("%s # <<< Malformed!", lineOutput)
lineOutput = fmt.Sprintf("%s # <<< Malformed!\n", lineOutput)
}

logrus.Infof(lineOutput)
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/goodhosts/cli/cmd"
"github.com/goodhosts/hostsfile"
"github.com/sirupsen/logrus"
easy "github.com/t-tomalak/logrus-easy-formatter"
"github.com/urfave/cli/v2"
)

Expand All @@ -20,6 +21,11 @@ func main() {
Before: func(ctx *cli.Context) error {
if ctx.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel)
} else {
// treat logrus like fmt.Print
logrus.SetFormatter(&easy.Formatter{
LogFormat: "%msg%",
})
}
if ctx.Bool("quiet") {
logrus.SetOutput(ioutil.Discard)
Expand Down

0 comments on commit d6eb6a6

Please sign in to comment.