diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 24b5adf..9ed2402 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,7 +5,7 @@ before: - go mod tidy builds: - - main: ./cmd/barrier + - main: ./cmd/adless env: - CGO_ENABLED=0 ldflags: diff --git a/Makefile b/Makefile index f694df5..7bcbc53 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -NAME=barrier +NAME=adless SRC_PATH=./cmd/$(NAME) BUILD_PATH=./build/$(NAME) diff --git a/README.md b/README.md index c2c21aa..ca9d920 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# barrier +# adless -Barrier is an easy-to-use CLI tool that blocks domains by using your system's hosts file. +Adless is an easy-to-use CLI tool that blocks domains by using your system's hosts file. Its main advantage is that it operates without running any background processes. Instead, it collects domains from different sources, combines them, and updates your hosts file. @@ -11,21 +11,21 @@ Instead, it collects domains from different sources, combines them, and updates Arch Linux (AUR): ```bash -yay -S barrier +yay -S adless-bin ``` ## Manual Installation -Download a binary from the [releases page](https://github.com/WIttyJudge/barrier/releases) for Linux, macOS or Windows. +Download a binary from the [releases page](https://github.com/WIttyJudge/adless/releases) for Linux, macOS or Windows. # Usage ``` NAME: - barrier - Local domains blocker writter in Go + adless - Local domains blocker writter in Go USAGE: - barrier [global options] command [command options] + adless [global options] command [command options] VERSION: v1.0.0 @@ -49,18 +49,18 @@ GLOBAL OPTIONS: # Configuration file -Barrier supports reading and writing configuration files. -The default configuration file is located at `$HOME/.config/barrier/config.yml`, +Adless supports reading and writing configuration files. +The default configuration file is located at `$HOME/.config/adless/config.yml`, but it can be redefined using `--config` flag or the following environment variables: -- BARRIER_CONFIG_PATH - Specifies the full path to the configuration file. -- BARRIER_CONFIG_HOME - Specifies the folder where the `config.yml` file is located. -- XDG_CONFIG_HOME - Specifies the base directory for user-specific configuration files. Barrier will look for `barrier/config.yml` within this directory. +- ADLESS_CONFIG_PATH - Specifies the full path to the configuration file. +- ADLESS_CONFIG_HOME - Specifies the folder where the `config.yml` file is located. +- XDG_CONFIG_HOME - Specifies the base directory for user-specific configuration files. Adless will look for `adless/config.yml` within this directory. To create a local configuration file, run: ```bash -barrier config init +adless config init ``` # TODO: diff --git a/cmd/barrier/main.go b/cmd/adless/main.go similarity index 96% rename from cmd/barrier/main.go rename to cmd/adless/main.go index 69921e2..9685d0f 100644 --- a/cmd/barrier/main.go +++ b/cmd/adless/main.go @@ -1,7 +1,7 @@ package main import ( - "barrier/internal/action" + "adless/internal/action" "fmt" "os" "sort" @@ -36,7 +36,7 @@ func setupApp() *cli.App { action := action.New() app := cli.NewApp() - app.Name = "barrier" + app.Name = "adless" app.Usage = "Local domains blocker writter in Go" app.UseShortOptionHandling = true app.Version = version diff --git a/go.mod b/go.mod index 4586af1..5c27469 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module barrier +module adless go 1.22.0 diff --git a/internal/action/action.go b/internal/action/action.go index 5a4f238..bdb7e4d 100644 --- a/internal/action/action.go +++ b/internal/action/action.go @@ -1,8 +1,8 @@ package action import ( - "barrier/internal/action/exit" - "barrier/internal/config" + "adless/internal/action/exit" + "adless/internal/config" "github.com/rs/zerolog" "github.com/urfave/cli/v2" diff --git a/internal/action/config.go b/internal/action/config.go index 996397b..447f308 100644 --- a/internal/action/config.go +++ b/internal/action/config.go @@ -1,8 +1,8 @@ package action import ( - "barrier/internal/action/exit" - "barrier/internal/config" + "adless/internal/action/exit" + "adless/internal/config" "github.com/urfave/cli/v2" ) diff --git a/internal/action/disable.go b/internal/action/disable.go index 3f98429..ee74506 100644 --- a/internal/action/disable.go +++ b/internal/action/disable.go @@ -1,8 +1,8 @@ package action import ( - "barrier/internal/action/exit" - "barrier/internal/hostsfile" + "adless/internal/action/exit" + "adless/internal/hostsfile" "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" diff --git a/internal/action/enable.go b/internal/action/enable.go index 46f0d14..60016d0 100644 --- a/internal/action/enable.go +++ b/internal/action/enable.go @@ -1,8 +1,8 @@ package action import ( - "barrier/internal/action/exit" - "barrier/internal/hostsfile" + "adless/internal/action/exit" + "adless/internal/hostsfile" "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" diff --git a/internal/action/restore.go b/internal/action/restore.go index 510a9b2..36ddc89 100644 --- a/internal/action/restore.go +++ b/internal/action/restore.go @@ -1,8 +1,8 @@ package action import ( - "barrier/internal/action/exit" - "barrier/internal/hostsfile" + "adless/internal/action/exit" + "adless/internal/hostsfile" "github.com/rs/zerolog/log" diff --git a/internal/action/status.go b/internal/action/status.go index 536bd04..b3e52d4 100644 --- a/internal/action/status.go +++ b/internal/action/status.go @@ -1,8 +1,8 @@ package action import ( - "barrier/internal/action/exit" - "barrier/internal/hostsfile" + "adless/internal/action/exit" + "adless/internal/hostsfile" "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" diff --git a/internal/action/update.go b/internal/action/update.go index 540ca47..b01a7fe 100644 --- a/internal/action/update.go +++ b/internal/action/update.go @@ -1,8 +1,8 @@ package action import ( - "barrier/internal/action/exit" - "barrier/internal/hostsfile" + "adless/internal/action/exit" + "adless/internal/hostsfile" "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" diff --git a/internal/config/config.go b/internal/config/config.go index 30051f2..5853e08 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -127,7 +127,7 @@ func Init() error { func Edit() error { location := location() - c, err := editor.Cmd("barrier", location) + c, err := editor.Cmd("adless", location) if err != nil { return err } @@ -145,19 +145,19 @@ func Edit() error { // location returns the location of the config file. func location() string { - if bcp := os.Getenv("BARRIER_CONFIG_PATH"); bcp != "" { + if bcp := os.Getenv("ADLESS_CONFIG_PATH"); bcp != "" { return bcp } - if bch := os.Getenv("BARRIER_CONFIG_HOME"); bch != "" { + if bch := os.Getenv("ADLESS_CONFIG_HOME"); bch != "" { return filepath.Join(bch, "config.yml") } if xdgConfig := os.Getenv("XDG_CONFIG_HOME"); xdgConfig != "" { - return filepath.Join(xdgConfig, "barrier", "config.yml") + return filepath.Join(xdgConfig, "adless", "config.yml") } - return filepath.Join(homeDir(), ".config", "barrier", "config.yml") + return filepath.Join(homeDir(), ".config", "adless", "config.yml") } // read reads config file by location in file system. diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 7740439..87378b0 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -11,14 +11,14 @@ import ( ) func TestLoad(t *testing.T) { - td, err := os.MkdirTemp("", "barrier-config") + td, err := os.MkdirTemp("", "adless-config") defer os.RemoveAll(td) require.NoError(t, err) t.Run("return default config if there is no local", func(t *testing.T) { - os.Setenv("BARRIER_CONFIG_HOME", "test") - defer os.Unsetenv("BARRIER_CONFIG_HOME") + os.Setenv("ADLESS_CONFIG_HOME", "test") + defer os.Unsetenv("ADLESS_CONFIG_HOME") config, err := Load() @@ -35,8 +35,8 @@ func TestLoad(t *testing.T) { _, err = testConfig.WriteString("invalid yml content") require.NoError(t, err) - os.Setenv("BARRIER_CONFIG_PATH", testConfig.Name()) - defer os.Unsetenv("BARRIER_CONFIG_PATH") + os.Setenv("ADLESS_CONFIG_PATH", testConfig.Name()) + defer os.Unsetenv("ADLESS_CONFIG_PATH") config, err := Load() @@ -52,8 +52,8 @@ func TestLoad(t *testing.T) { _, err = testConfig.WriteString("blocklists:\n") require.NoError(t, err) - os.Setenv("BARRIER_CONFIG_PATH", testConfig.Name()) - defer os.Unsetenv("BARRIER_CONFIG_PATH") + os.Setenv("ADLESS_CONFIG_PATH", testConfig.Name()) + defer os.Unsetenv("ADLESS_CONFIG_PATH") config, err := Load() @@ -69,8 +69,8 @@ func TestLoad(t *testing.T) { _, err = testConfig.WriteString("blocklists:\n- target: https://test.com") require.NoError(t, err) - os.Setenv("BARRIER_CONFIG_PATH", testConfig.Name()) - defer os.Unsetenv("BARRIER_CONFIG_PATH") + os.Setenv("ADLESS_CONFIG_PATH", testConfig.Name()) + defer os.Unsetenv("ADLESS_CONFIG_PATH") config, err := Load() @@ -80,7 +80,7 @@ func TestLoad(t *testing.T) { } func TestLoadByUser(t *testing.T) { - td, err := os.MkdirTemp("", "barrier-config") + td, err := os.MkdirTemp("", "adless-config") defer os.RemoveAll(td) require.NoError(t, err) @@ -121,20 +121,20 @@ func TestLoadByUser(t *testing.T) { } func TestLocation(t *testing.T) { - t.Run("BARRIER_CONFIG_PATH environment variable", func(t *testing.T) { - bcp := path.Join(homeDir(), ".config", "test_barrier", "config.yml") + t.Run("ADLESS_CONFIG_PATH environment variable", func(t *testing.T) { + bcp := path.Join(homeDir(), ".config", "test_adless", "config.yml") - os.Setenv("BARRIER_CONFIG_PATH", bcp) - defer os.Unsetenv("BARRIER_CONFIG_PATH") + os.Setenv("ADLESS_CONFIG_PATH", bcp) + defer os.Unsetenv("ADLESS_CONFIG_PATH") assert.Equal(t, location(), bcp) }) - t.Run("BARRIER_CONFIG_HOME environment variable", func(t *testing.T) { - bch := path.Join(homeDir(), ".config", "test_barrier") + t.Run("ADLESS_CONFIG_HOME environment variable", func(t *testing.T) { + bch := path.Join(homeDir(), ".config", "test_adless") - os.Setenv("BARRIER_CONFIG_HOME", bch) - defer os.Unsetenv("BARRIER_CONFIG_HOME") + os.Setenv("ADLESS_CONFIG_HOME", bch) + defer os.Unsetenv("ADLESS_CONFIG_HOME") expected := filepath.Join(bch, "config.yml") assert.Equal(t, location(), expected) @@ -146,18 +146,18 @@ func TestLocation(t *testing.T) { os.Setenv("XDG_CONFIG_HOME", xdgConfig) defer os.Unsetenv("XDG_CONFIG_HOME") - expected := filepath.Join(xdgConfig, "barrier", "config.yml") + expected := filepath.Join(xdgConfig, "adless", "config.yml") assert.Equal(t, location(), expected) }) t.Run("default location", func(t *testing.T) { - expected := filepath.Join(homeDir(), ".config", "barrier", "config.yml") + expected := filepath.Join(homeDir(), ".config", "adless", "config.yml") assert.Equal(t, location(), expected) }) } func TestRead(t *testing.T) { - td, err := os.MkdirTemp("", "barrier-config") + td, err := os.MkdirTemp("", "adless-config") defer os.RemoveAll(td) require.NoError(t, err) @@ -204,7 +204,7 @@ func TestHomeDir(t *testing.T) { os.Setenv("SUDO_USER", "root") defer os.Unsetenv("SUDO_USER") - expected := "/root/.config/barrier/config.yml" + expected := "/root/.config/adless/config.yml" assert.Equal(t, location(), expected) }) } diff --git a/internal/hostsfile/file.go b/internal/hostsfile/file.go index 4c630bd..339f2e3 100644 --- a/internal/hostsfile/file.go +++ b/internal/hostsfile/file.go @@ -1,7 +1,7 @@ package hostsfile import ( - "barrier/pkg/fsutil" + "adless/pkg/fsutil" "errors" "fmt" "os" @@ -11,9 +11,9 @@ import ( ) const ( - StartTag = "###### START barrier\n" - EndTag = "###### END barrier" - DescriptionComment = "# Generated by the barrier CLI tool. DO NOT EDIT!\n" + StartTag = "###### START adless\n" + EndTag = "###### END adless" + DescriptionComment = "# Generated by the adless CLI tool. DO NOT EDIT!\n" ) var ( diff --git a/internal/hostsfile/processor.go b/internal/hostsfile/processor.go index 1c50fa8..2225436 100644 --- a/internal/hostsfile/processor.go +++ b/internal/hostsfile/processor.go @@ -1,8 +1,8 @@ package hostsfile import ( - "barrier/internal/config" - "barrier/internal/http" + "adless/internal/config" + "adless/internal/http" "fmt" "slices" "strings" diff --git a/pkg/fsutil/fsutil_test.go b/pkg/fsutil/fsutil_test.go index c500e14..ad3e0b3 100644 --- a/pkg/fsutil/fsutil_test.go +++ b/pkg/fsutil/fsutil_test.go @@ -9,7 +9,7 @@ import ( ) func TestCopyFile(t *testing.T) { - td, err := os.MkdirTemp("", "barrier-fsutil") + td, err := os.MkdirTemp("", "adless-fsutil") require.NoError(t, err) defer os.RemoveAll(td)