Skip to content

Commit b5c7075

Browse files
authored
Merge pull request #5 from tommyblue/master
Add 'show' argument to print the /etc/hosts file
2 parents fd1228d + dc65154 commit b5c7075

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

util/cmd/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,4 @@ func Execute() {
143143
fmt.Println(err)
144144
os.Exit(1)
145145
}
146-
return
147146
}

util/cmd/show.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func init() {
10+
rootCmd.AddCommand(showCmd)
11+
}
12+
13+
var showCmd = &cobra.Command{
14+
Use: "show",
15+
Short: "Show hostnames in /etc/hosts",
16+
Long: `Show the content of the /etc/hosts file `,
17+
Args: func(cmd *cobra.Command, args []string) error {
18+
return nil
19+
},
20+
Run: func(cmd *cobra.Command, args []string) {
21+
ShowHosts()
22+
},
23+
}
24+
25+
func ShowHosts() {
26+
fmt.Print(etcHosts.RenderHostsFile())
27+
}

0 commit comments

Comments
 (0)