Skip to content
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

Config updates #9

Merged
merged 3 commits into from
Mar 8, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
11 changes: 11 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ checksum:
name_template: "checksums.txt"
changelog:
skip: true
brews:
- tap:
owner: marwanhawari
name: homebrew-tap
folder: Formula
commit_author:
name: Marwan Hawari
email: [email protected]
license: "MIT"
homepage: "https://github.com/marwanhawari/stew"
description: "An independent package manager for compiled binaries"
64 changes: 52 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,41 @@
* Easily distribute binaries across teams and private repositories.
* Get the latest releases ahead of other package managers.
* Rapidly browse, install, and experiment with different projects.
* Isolated `~/.stew/` directory.
* [Configure](https://github.com/marwanhawari/stew/blob/main/config.md) where to install binaries.
* No need for `sudo`.
* Portable [`Stewfile`](https://github.com/marwanhawari/stew/blob/main/examples/Stewfile) with optional pinned versioning.

![demo](https://github.com/marwanhawari/stew/raw/main/assets/demo.gif)

# Installation
Stew supports Linux, macOS, and Windows:
Stew supports Linux, macOS, and Windows.

### Install a pre-compiled binary:

* Install using `curl`:
```
curl -fsSL https://raw.githubusercontent.com/marwanhawari/stew/main/install.sh | bash
```

* Install using `brew`:
```
brew install marwanhawari/tap/stew
```

* Download a pre-compiled binary from the [releases page](https://github.com/marwanhawari/stew/releases).

### Install from source:

* Install the latest released version:
```
curl -fsSL https://raw.githubusercontent.com/marwanhawari/stew/main/install.sh | sh
go install github.com/marwanhawari/stew@latest
```

* Install the latest unreleased source:
```
git clone https://github.com/marwanhawari/stew
cd stew
go install .
```

# Usage
Expand Down Expand Up @@ -89,6 +114,12 @@ stew uninstall rg # Uninstall using the name of the binary directly
stew uninstall --all # Uninstall all binaries
```

### Rename
```sh
# Rename an installed binary using an interactive UI
stew rename rg # Rename using the name of the binary directly
```

### List
```sh
# List installed binaries
Expand All @@ -98,19 +129,28 @@ stew list --tags > Stewfile # Pin tags
stew list --tags --assets > Stewfile # Pin tags and assets
```

### Config
```sh
# Configure the stew file paths using an interactive UI
stew config # Automatically updates the stew.config.json
```

# FAQ
### Why couldn't `stew` automatically find any binaries for X repo?
The repo probably uses an unconventional naming scheme for their binaries. You can always manually select the release asset.

### I've installed `stew` but the command is still not found.
The `stew` [install script](https://github.com/marwanhawari/stew/blob/main/install.sh) attempts to add `~/.stew/bin` to `PATH` in your `.zshrc` or `.bashrc` file. You will also need to start a new terminal session for the changes to take effect. Make sure that `~/.stew/bin` is in your `PATH` environment variable.

### Will `stew` work with private GitHub repositories?
Yes, `stew` will automatically detect if you have a `GITHUB_TOKEN` environment variable and allow you to access binaries from your private repositories.

### How do I uninstall `stew`?
Simply run `rm -rf $HOME/.stew/` and optionally remove this line
```
export PATH="$HOME/.stew/bin:$PATH"
```
from your `.zshrc` or `.bashrc` file.
### Where does `stew` install binaries?
The default installation path will depend on your OS:
| Linux/macOS | Windows |
| ------------ | ---------- |
| `~/.local/bin` | `~/AppData/Local/stew/bin` |

However, this location can be [configured](https://github.com/marwanhawari/stew/blob/main/config.md).

Make sure that the installation path is in your `PATH` environment variable. Otherwise, you won't be able to use any of the binaries installed by `stew`.

### I've installed `stew` but the command is still not found.
If you install `stew` with the [curl install script](https://github.com/marwanhawari/stew/blob/main/install.sh), the `stew` binary will be installed in the `stewBinPath` you provided. The install script also attempts to add the `stewBinPath` to `PATH` in your `.zshrc` or `.bashrc` file. You will need to start a new terminal session for the changes to take effect. Make sure that the `stewBinPath` is in your `PATH` environment variable.
5 changes: 1 addition & 4 deletions cmd/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (
func Browse(cliInput string) {

userOS, userArch, _, systemInfo, err := stew.Initialize()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
stew.CatchAndExit(err)

sp := constants.LoadingSpinner

Expand Down
29 changes: 17 additions & 12 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@ package cmd
import (
"fmt"
"os"
"runtime"

"github.com/marwanhawari/stew/constants"
stew "github.com/marwanhawari/stew/lib"
)

func Config() {

userOS, _, stewConfig, _, err := stew.Initialize()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

userOS := runtime.GOOS
stewConfigFilePath, err := stew.GetStewConfigFilePath(userOS)
stew.CatchAndExit(err)
configExists, err := stew.PathExists(stewConfigFilePath)
stew.CatchAndExit(err)

inputStewPath, err := stew.PromptInput("Set the stewPath. This will contain all stew data other than the binaries.", stewConfig.StewPath)
if !configExists {
_, err := stew.NewStewConfig(userOS)
stew.CatchAndExit(err)
return
}

defaultStewPath, err := stew.GetDefaultStewPath(userOS)
stew.CatchAndExit(err)
inputStewBinPath, err := stew.PromptInput("Set the stewBinPath. This is where the binaries will be installed by stew.", stewConfig.StewBinPath)
defaultStewBinPath, err := stew.GetDefaultStewBinPath(userOS)
stew.CatchAndExit(err)

fullStewPath, err := stew.ResolveTilde(inputStewPath)
stew.CatchAndExit(err)
fullStewBinPath, err := stew.ResolveTilde(inputStewBinPath)
newStewPath, newStewBinPath, err := stew.PromptConfig(defaultStewPath, defaultStewBinPath)
stew.CatchAndExit(err)

newStewConfig := stew.StewConfig{StewPath: fullStewPath, StewBinPath: fullStewBinPath}
newStewConfig := stew.StewConfig{StewPath: newStewPath, StewBinPath: newStewBinPath}
err = stew.WriteStewConfigJSON(newStewConfig, stewConfigFilePath)
stew.CatchAndExit(err)

fmt.Printf("📄 Updated %v\n", constants.GreenColor(stewConfigFilePath))

pathVariable := os.Getenv("PATH")
stew.ValidateStewBinPath(newStewBinPath, pathVariable)
}
5 changes: 1 addition & 4 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ func Install(cliInputs []string) {
var err error

userOS, userArch, _, systemInfo, err := stew.Initialize()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
stew.CatchAndExit(err)

for _, cliInput := range cliInputs {
if strings.Contains(cliInput, "Stewfile") {
Expand Down
6 changes: 1 addition & 5 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"os"

stew "github.com/marwanhawari/stew/lib"
)
Expand All @@ -11,10 +10,7 @@ import (
func List(cliTagsFlag bool, cliAssetsFlag bool) {

userOS, userArch, _, systemInfo, err := stew.Initialize()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
stew.CatchAndExit(err)

stewLockFilePath := systemInfo.StewLockFilePath

Expand Down
5 changes: 1 addition & 4 deletions cmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (
func Rename(cliInput string) {

userOS, userArch, _, systemInfo, err := stew.Initialize()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
stew.CatchAndExit(err)

err = stew.ValidateCLIInput(cliInput)
stew.CatchAndExit(err)
Expand Down
6 changes: 1 addition & 5 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"os"

"github.com/marwanhawari/stew/constants"
stew "github.com/marwanhawari/stew/lib"
Expand All @@ -12,10 +11,7 @@ import (
func Uninstall(cliFlag bool, binaryName string) {

userOS, userArch, _, systemInfo, err := stew.Initialize()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
stew.CatchAndExit(err)

if cliFlag && binaryName != "" {
stew.CatchAndExit(stew.CLIFlagAndInputError{})
Expand Down
5 changes: 1 addition & 4 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (
func Upgrade(cliFlag bool, binaryName string) {

userOS, userArch, _, systemInfo, err := stew.Initialize()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
stew.CatchAndExit(err)

if cliFlag && binaryName != "" {
stew.CatchAndExit(stew.CLIFlagAndInputError{})
Expand Down
23 changes: 23 additions & 0 deletions config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Configuration
`stew` can be configured with a `stew.config.json` file. The location of this file will depend on your OS:
|Linux/macOS | Windows |
| ------------ | ---------- |
| `$XDG_CONFIG_HOME/stew` or `~/.config/stew` | `~/AppData/Local/stew/Config` |

You can configure 2 aspects of `stew`:
1. The `stewPath`: this is where `stew` data is stored.
2. The `stewBinPath`: this is where `stew` installs binaries

The default locations for these are:
| | Linux/macOS | Windows |
| ------------ | ------------ | ---------- |
| `stewPath` | `$XDG_DATA_HOME/stew` or `~/.local/share/stew` | `~/AppData/Local/stew` |
| `stewBinPath` | `~/.local/bin` | `~/AppData/Local/stew/bin` |

There are multiple ways to configure these:
* When first installing `stew`:
* If you install with the [curl install script](https://github.com/marwanhawari/stew/blob/main/install.sh) you will be immediately prompted to set these. This will create a `stew.config.json` file.
* If you install the `stew` binary itself (without the curl install script - i.e. with `brew` or by downloading it directly from the releases page), `stew` will look for a `stew.config.json` file. If it cannot find one, then you will be prompted to set the configuration values.

* After `stew` is installed, you can use the `stew config` command to set the configuration values.
* At any time, you can manually create or edit the `stew.config.json` file. It should have values for `stewPath` and `stewBinPath`.
13 changes: 9 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ os=""
arch=""
exe=""
defaultStewPath=""
defaultStewBinPath=""
configPath=""

# Detect os
Expand All @@ -23,6 +24,8 @@ case "$(uname -s)" in
defaultStewPath="$XDG_DATA_HOME/stew"
fi

defaultStewBinPath="$HOME/.local/bin"

if [ -z "$XDG_CONFIG_HOME" ]
then
configPath="$HOME/.config/stew"
Expand All @@ -39,6 +42,8 @@ case "$(uname -s)" in
defaultStewPath="$XDG_DATA_HOME/stew"
fi

defaultStewBinPath="$HOME/.local/bin"

if [ -z "$XDG_CONFIG_HOME" ]
then
configPath="$HOME/.config/stew"
Expand All @@ -50,6 +55,7 @@ case "$(uname -s)" in
os="windows"
exe=".exe"
defaultStewPath="$HOME/AppData/Local/stew"
defaultStewBinPath="$HOME/AppData/Local/stew/bin"
configPath="$HOME/AppData/Local/stew/Config"
;;
esac
Expand Down Expand Up @@ -97,10 +103,10 @@ else
fi
fi

read -r -t 60 -p "Set the stewBinPath. This is where the binaries will be installed by stew. (${defaultStewPath}/bin): " stewBinPathInput
read -r -t 60 -p "Set the stewBinPath. This is where the binaries will be installed by stew. (${defaultStewBinPath}): " stewBinPathInput
if [ -z "$stewBinPathInput" ]
then
stewBinPath="${defaultStewPath}/bin"
stewBinPath="${defaultStewBinPath}"
else
stewBinPath="${stewBinPathInput/#~/$HOME}"
stewBinPath="${stewBinPath/#\$HOME/$HOME}"
Expand All @@ -111,15 +117,14 @@ else
fi
fi

mkdir -p "${stewPath}/bin"
mkdir -p "${stewPath}/pkg"
mkdir -p "${stewBinPath}"
mkdir -p "${configPath}"

echo "{
\"stewPath\": \"${stewPath}\",
\"stewBinPath\": \"${stewBinPath}\"
}" > "${configPath}/config.json"
}" > "${configPath}/stew.config.json"

# 2. Download the stew binary
curl -o "${stewBinPath}/stew${exe}" -fsSL https://github.com/marwanhawari/stew/releases/latest/download/stew-${os}-${arch}${exe}
Expand Down
Loading