Reformat some help stuff

pull/13/head
Chris Bednarski 9 years ago
parent f8976dd0c2
commit 39db28a677

@ -16,17 +16,15 @@ func getArgs() []string {
const help = `an idempotent tool for managing /etc/hosts
* WARNING: This program is BETA and not all commands are implemented.
* Commands will exit 0 or 1 in a sensible way to facilitate scripting.
* Commands will exit 0 or 1 in a sensible way so you can use the exit code for
bash and make scripting. Add -h to any command to learn more about it.
* Hostess operates on /etc/hosts by default. Specify the HOSTESS_FILE
environment variable to change this.
* You can specify the HOSTESS_FILE environment variable to operate on a
file other than /etc/hosts
* Run 'hostess fix -n' to preview changes hostess will make to your hostsfile.
* To preview a hostess-managed hostsfile run ` + "`" + `hostess fix -n` + "`" + `
* Report bugs and feedback at https://github.com/cbednarski/hostess`
* Report bugs and feedback at https://github.com/cbednarski/hostess
`
func main() {
app := cli.NewApp()
@ -37,74 +35,74 @@ func main() {
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "f",
Usage: "Force write to the hostsfile even if there are errors or conflicts",
Usage: "operate even if there are errors or conflicts",
},
cli.BoolFlag{
Name: "n",
Usage: "No-op. Show changes but don't write them.",
Usage: "no-op. Show changes but don't write them.",
},
cli.BoolFlag{
Name: "q",
Usage: "Quiet. Supress error messages",
Usage: "quiet operation -- no notices",
},
cli.BoolFlag{
Name: "s",
Usage: "Silent. Supress success messages (implies -q)",
Usage: "silent operation -- no errors (implies -q)",
},
}
app.Commands = []cli.Command{
{
Name: "add",
Usage: "Add (or update) a hosts entry",
Usage: "add (or update) a hosts entry",
Action: hostess.Add,
Flags: app.Flags,
},
{
Name: "del",
Usage: "Delete a hosts entry",
Usage: "delete a hosts entry",
Action: hostess.Del,
Flags: app.Flags,
},
{
Name: "has",
Usage: "Exit 0 if entry exists, 1 if not",
Usage: "exit 0 if entry exists, 1 if not",
Action: hostess.Has,
Flags: app.Flags,
},
{
Name: "off",
Usage: "Disable a hosts entry (don't delete it)",
Usage: "disable a hosts entry (don't delete it)",
Action: hostess.Off,
Flags: app.Flags,
},
{
Name: "on",
Usage: "Enable a hosts entry (if if exists)",
Usage: "enable a hosts entry (if if exists)",
Action: hostess.On,
Flags: app.Flags,
},
{
Name: "ls, list",
Usage: "List entries in the hosts file",
Usage: "list entries in the hosts file",
Action: hostess.Ls,
Flags: app.Flags,
},
{
Name: "fix",
Usage: "Reformat the hosts file based on hostess' rules",
Usage: "reformat the hosts file based on hostess' rules",
Action: hostess.Fix,
Flags: app.Flags,
},
{
Name: "dump",
Usage: "Dump the hosts file as JSON",
Usage: "dump the hosts file as JSON",
Action: hostess.Dump,
Flags: app.Flags,
},
{
Name: "apply",
Usage: "Apply a JSON hosts dict to your hosts file",
Usage: "apply a JSON hosts dict to your hosts file",
Action: hostess.Apply,
Flags: app.Flags,
},

@ -7,22 +7,22 @@ import (
"strings"
)
// MaybeErrorln will print an error message unless -q is passed
// MaybeErrorln will print an error message unless -s is passed
func MaybeErrorln(c *cli.Context, message string) {
if !c.Bool("q") && !c.Bool("s") {
if !c.Bool("s") {
os.Stderr.WriteString(fmt.Sprintf("%s: %s\n", c.Command.Name, message))
}
}
// MaybeError will print an error message unless -q is passed and then exit
// MaybeError will print an error message unless -s is passed and then exit
func MaybeError(c *cli.Context, message string) {
MaybeErrorln(c, message)
os.Exit(1)
}
// MaybePrintln will print a message unless -s is passed
// MaybePrintln will print a message unless -q or -s is passed
func MaybePrintln(c *cli.Context, message string) {
if !c.Bool("s") {
if !c.Bool("q") && !c.Bool("s") {
fmt.Println(message)
}
}

Loading…
Cancel
Save