This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
forked from goodhosts/cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request goodhosts#3 from goodhosts/backup-restore
added backup, restore and edit
- Loading branch information
Showing
8 changed files
with
132 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func Edit() *cli.Command { | ||
return &cli.Command{ | ||
Name: "edit", | ||
Aliases: []string{"e"}, | ||
Usage: "Open hosts file in an editor, default vim", | ||
Action: edit, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "editor", | ||
Aliases: []string{"e"}, | ||
Usage: "Which file editor to use, defaults vim", | ||
Value: "vim", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func edit(c *cli.Context) error { | ||
hostsfile, err := loadHostsfile(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd := exec.Command(c.String("editor"), hostsfile.Path) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stdin = os.Stdin | ||
cmd.Stderr = os.Stderr | ||
return cmd.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters