8000 Add support for go install by fjammes · Pull Request #23 · txn2/txeh · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for go install #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ builds:
- id: txeh
# Path to main.go file.
# Default is `main.go`
main: ./util/txeh.go
main: ./txeh/txeh.go
binary: txeh

env:
Expand All @@ -29,7 +29,7 @@ builds:
- "6"
- "7"

ldflags: "-s -w -X github.com/txn2/txeh/util/cmd.Version={{.Version}}"
ldflags: "-s -w -X github.com/txn2/txeh/txeh/cmd.Version={{.Version}}"

checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
Expand Down Expand Up @@ -91,4 +91,4 @@ snapcrafts:
description: |
Kubernetes bulk port forwarding utility.
grade: stable
confinement: classic
confinement: classic
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@ A computer's [/etc/hosts] file is a powerful utility for developers and system a

MacOS [homebrew](https://brew.sh) users can `brew install txn2/tap/txeh`, otherwise see [releases](https://github.com/txn2/txeh/releases) for packages and binaries for a number of distros and architectures including Windows, Linux and Arm based systems.

Complie and run from source (dependencies are vendored):
#### Install with go install

When installing with Go please use the latest stable Go release. At least go1.16 or greater is required.

To install use: `go install github.com/txn2/txeh/txeh@master`

If you are building from a local source clone, use `go install ./txeh` from the top-level directory of the clone.

go install will typically put the txeh binary inside the bin directory under go env GOPATH, see Go’s [Compile and install packages and dependencies](https://golang.org/cmd/go/#hdr-Compile_and_install_packages_and_dependencies) for more on this. You may need to add that directory to your $PATH if you encounter the error `txeh: command not found` after installation, you can find a guide for adding a directory to your PATH at https://gist.github.com/nex3/c395b2f8fd4b02068be37c961301caa7#file-path-md.

#### Compile and run from source

dependencies are vendored:
```
go run ./util/txeh.go
go run ./txeh/txeh.go
```

### Use
Expand Down Expand Up @@ -69,7 +81,7 @@ sudo txeh add 127.0.0.1 test test.two
# remove the hostname "test"
sudo txeh remove host test

# remove multiple hostnames
# remove multiple hostnames
sudo txeh remove host test test2 test.two

# remove an IP address and all the hosts that point to it
Expand Down Expand Up @@ -129,27 +141,27 @@ func main() {
hosts.AddHost("127.100.100.100", "test")
hosts.AddHost("127.100.100.101", "logstash")
hosts.AddHosts("127.100.100.102", []string{"a", "b", "c"})

hosts.RemoveHosts([]string{"example", "example.machine", "example.machine.example.com"})
hosts.RemoveHosts(strings.Fields("example2 example.machine2 example.machine.example.com2"))


hosts.RemoveAddress("127.1.27.1")

removeList := []string{
"127.1.27.15",
"127.1.27.14",
"127.1.27.13",
}

hosts.RemoveAddresses(removeList)

hfData := hosts.RenderHostsFile()

// if you like to see what the outcome will
// look like
fmt.Println(hfData)

hosts.Save()
// or hosts.SaveAs("./test.hosts")
}
Expand All @@ -160,12 +172,12 @@ func main() {

Build test release:
```bash
goreleaser --skip-publish --rm-dist --skip-validate
goreleaser --skip-publish --clean --skip-validate
```

Build and release:
```bash
GITHUB_TOKEN=$GITHUB_TOKEN goreleaser --rm-dist
GITHUB_TOKEN=$GITHUB_TOKEN goreleaser --clean
```

### License
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion util/cmd/root.go → txeh/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
| |___ _____| |__
| __\ \/ / _ \ '_ \
| |_ > < __/ | | |
\__/_/\_\___|_| |_| v` + Version + `
\__/_/\_\_ F438 __|_| |_| Version: ` + VersionFromBuild() + `

Add, remove and re-associate hostname entries in your /etc/hosts file.
Read more including usage as a Go library at https://github.com/txn2/txeh`,
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions txeh/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cmd

import (
"fmt"
"runtime/debug"

"github.com/spf13/cobra"
)

var Version = "0.0.0"

func init() {
rootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of txeh",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
version := VersionFromBuild()
fmt.Printf("txeh Version: %s\n", version)
},
}

// Version returns the version of txeh binary
func VersionFromBuild() (version string) {
// Version is managed with goreleaser
if Version != "0.0.0" {
return Version
}
// Version is managed by "go install"
b, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
if b == nil {
version = "nil"
} else {
version = b.Main.Version
}
return version
}
2 changes: 1 addition & 1 deletion util/txeh.go → txeh/txeh.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "github.com/txn2/txeh/util/cmd"
import "github.com/txn2/txeh/txeh/cmd"

func main() {
cmd.Execute()
Expand Down
22 changes: 0 additions & 22 deletions util/cmd/version.go

This file was deleted.

0