Skip to content

Commit

Permalink
comply with golangci-lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
guumaster committed Apr 16, 2020
1 parent 402b798 commit 922768a
Show file tree
Hide file tree
Showing 61 changed files with 743 additions and 649 deletions.
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
linters:
disable:
- goimports
- gochecknoglobals
- gochecknoinits
- prealloc
enable-all: true

# all available settings of specific linters
linters-settings:
funlen:
lines: 120
statements: 80
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![License][license-badge]][license-link]
[![All Contributors][all-contributors-badge]][all-contributors-link]
[![Coverage][coverage-badge]][coverage-link]
[![Mentioned in Awesome Go][awesome-go-badge]][awesome-go-link]

# hostctl

Expand Down Expand Up @@ -117,6 +118,9 @@ This project follows the [all-contributors](https://github.com/all-contributors/
[coverage-badge]: https://sonarcloud.io/api/project_badges/measure?project=guumaster_hostctl&metric=coverage
[coverage-link]: https://sonarcloud.io/dashboard?id=guumaster_hostctl

[awesome-go-badge]: https://awesome.re/mentioned-badge.svg
[awesome-go-link]: https://github.com/avelino/awesome-go

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[all-contributors-badge]: https://img.shields.io/badge/contributors-7-blue.svg
<!-- ALL-CONTRIBUTORS-BADGE:END -->
Expand Down
42 changes: 42 additions & 0 deletions cmd/hostctl/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// contains docs about the command
/*
__ __ __ __
/ /_ ____ _____ / /_ _____ / /_ / /
/ __ \ / __ \ / ___/ / __/ / ___/ / __/ / /
/ / / // /_/ / (__ ) / /_ / /__ / /_ / /
/_/ /_/ \____/ /____/ \__/ \___/ \__/ /_/
hostctl is a CLI tool to manage your hosts file with ease.
You can have multiple profiles, enable/disable exactly what
you need each time with a simple interface.
Usage:
hostctl [command]
Available Commands:
add Add content to a profile in your hosts file.
backup Creates a backup copy of your hosts file
disable Disable a profile from your hosts file.
enable Enable a profile on your hosts file.
help Help about any command
list Shows a detailed list of profiles on your hosts file.
remove Remove a profile from your hosts file.
replace Replace content to a profile in your hosts file.
restore Restore hosts file content from a backup file.
status Shows a list of profile names and statuses on your hosts file.
sync Sync some system IPs with a profile.
toggle Change status of a profile on your hosts file.
Flags:
-c, --column strings Columns to show on lists
-h, --help help for hostctl
--host-file string Hosts file path (default "/etc/hosts")
-q, --quiet Run command without output
--raw Output without table borders
-v, --version version for hostctl
Use "hostctl [command] --help" for more information about a command.
*/
package main
1 change: 1 addition & 0 deletions cmd/hostctl/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// package main contains CLI entrypoint
package main

import "github.com/guumaster/hostctl/pkg/cmd"
Expand Down
34 changes: 0 additions & 34 deletions doc.go

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/cmd/add_domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Test_AddDomains(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
const expected = `
+----------+--------+-----------+----------------+
| PROFILE | STATUS | IP | DOMAIN |
+----------+--------+-----------+----------------+
Expand All @@ -54,7 +54,7 @@ func Test_AddDomains(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
const expected = `
+------------+--------+-----------+----------------+
| PROFILE | STATUS | IP | DOMAIN |
+------------+--------+-----------+----------------+
Expand All @@ -79,7 +79,7 @@ func Test_AddDomains(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
const expected = `
+----------+--------+-----------+-----------------+
| PROFILE | STATUS | IP | DOMAIN |
+----------+--------+-----------+-----------------+
Expand All @@ -90,5 +90,4 @@ func Test_AddDomains(t *testing.T) {
`
assert.Contains(t, actual, expected)
})

}
9 changes: 5 additions & 4 deletions pkg/cmd/add_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ If the profile already exists it will be overwritten.
}

func init() {

addCmd.Flags().StringP("from", "f", "", "file to read")
addCmd.PersistentFlags().DurationP("wait", "w", -1, "Enables a profile for a specific amount of time")
addCmd.PersistentFlags().BoolP("uniq", "u", false, "only keep uniq domains per IP")
Expand All @@ -50,7 +49,6 @@ func init() {

addDomainsCmd.Flags().String("ip", "127.0.0.1", "domains ip")
addCmd.AddCommand(addDomainsCmd)

}

func makeAddReplace(action string) func(cmd *cobra.Command, profiles []string) error {
Expand All @@ -70,8 +68,11 @@ func makeAddReplace(action string) func(cmd *cobra.Command, profiles []string) e

in := cmd.InOrStdin()

var r io.Reader
var err error
var (
r io.Reader
err error
)

if isPiped() || in != os.Stdin {
r = in
} else {
Expand Down
19 changes: 9 additions & 10 deletions pkg/cmd/add_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Test_Add(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
const expected = `
+---------+--------+-----------+------------+
| PROFILE | STATUS | IP | DOMAIN |
+---------+--------+-----------+------------+
Expand All @@ -56,11 +56,10 @@ func Test_Add(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
const expected = `
`
assert.Contains(t, actual, expected)
})

}

func Test_ReplaceStdin(t *testing.T) {
Expand All @@ -70,10 +69,11 @@ func Test_ReplaceStdin(t *testing.T) {
defer os.Remove(tmp.Name())

b := bytes.NewBufferString("")
cmd.SetOut(b)

in := strings.NewReader(`3.3.3.3 stdin.replaced.loc`)
cmd.SetOut(b)
cmd.SetIn(in)

cmd.SetArgs([]string{"replace", "profile1", "--host-file", tmp.Name()})

err := cmd.Execute()
Expand All @@ -83,14 +83,13 @@ func Test_ReplaceStdin(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
assert.Contains(t, actual, `
+----------+--------+---------+--------------------+
| PROFILE | STATUS | IP | DOMAIN |
+----------+--------+---------+--------------------+
| profile1 | on | 3.3.3.3 | stdin.replaced.loc |
+----------+--------+---------+--------------------+
`
assert.Contains(t, actual, expected)
`)
}

func Test_ReplaceFile(t *testing.T) {
Expand All @@ -100,6 +99,7 @@ func Test_ReplaceFile(t *testing.T) {
5.5.5.5 replaced.loc
5.5.5.6 replaced2.loc
`)

tmp := makeTempHostsFile(t, "replaceFileCmd")
defer os.Remove(tmp.Name())

Expand All @@ -116,13 +116,12 @@ func Test_ReplaceFile(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
assert.Contains(t, actual, `
+---------+--------+---------+---------------+
| PROFILE | STATUS | IP | DOMAIN |
+---------+--------+---------+---------------+
| awesome | on | 5.5.5.5 | replaced.loc |
| awesome | on | 5.5.5.6 | replaced2.loc |
+---------+--------+---------+---------------+
`
assert.Contains(t, actual, expected)
`)
}
1 change: 1 addition & 0 deletions pkg/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ func init() {
if err != nil {
log.Fatal(err)
}

backupCmd.Flags().String("path", cwd, "A path to save the backup")
}
5 changes: 2 additions & 3 deletions pkg/cmd/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Test_Backup(t *testing.T) {
assert.NoError(t, err)

actual := "\n" + string(out)
expected := `
assert.Contains(t, actual, `
+----------+--------+-----------+------------+
| PROFILE | STATUS | IP | DOMAIN |
+----------+--------+-----------+------------+
Expand All @@ -39,6 +39,5 @@ func Test_Backup(t *testing.T) {
| profile2 | off | 127.0.0.1 | first.loc |
| profile2 | off | 127.0.0.1 | second.loc |
+----------+--------+-----------+------------+
`
assert.Contains(t, actual, expected)
`)
}
54 changes: 0 additions & 54 deletions pkg/cmd/disable.go

This file was deleted.

Loading

0 comments on commit 922768a

Please sign in to comment.