Skip to content

Commit

Permalink
Merge branch 'main' into personal-access-token
Browse files Browse the repository at this point in the history
  • Loading branch information
sasial-dev committed Jul 3, 2022
2 parents ccbbc51 + 188f99d commit 884f848
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 42 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
rust_version: [stable, 1.58.0]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
# https://doc.rust-lang.org/rustc/platform-support.html
include:
- host: linux
os: ubuntu-latest
os: ubuntu-18.04
target: x86_64-unknown-linux-gnu
label: linux-x86_64

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
*.snap.new
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

## Unreleased Changes

## [0.2.5] (July 2, 2022)
* Improved `self-install` behavior. ([#20])

[#20]: https://github.com/LPGhatguy/aftman/pull/20
[0.2.5]: https://github.com/LPGhatguy/aftman/releases/tag/v0.2.5

## [0.2.4] (July 1, 2022)
* Added support for `aftman self-install` on Unix platform. ([#16])
* Fixed Linux releases running on systems with an older glibc.

[#16]: https://github.com/LPGhatguy/aftman/pull/16
[0.2.4]: https://github.com/LPGhatguy/aftman/releases/tag/v0.2.4

## [0.2.3] (May 24, 2022)
* Fixed subprocesses living forever on Unix platforms. ([#13])
* Aftman now correctly marks executables as executable on Unix platforms. ([#14])

[#13]: https://github.com/LPGhatguy/aftman/pull/13
[#14]: https://github.com/LPGhatguy/aftman/pull/14
[0.2.2]: https://github.com/LPGhatguy/aftman/releases/tag/v0.2.3
[0.2.3]: https://github.com/LPGhatguy/aftman/releases/tag/v0.2.3

## [0.2.2] (May 23, 2022)
* Fixed building on non-Windows platforms
Expand Down
60 changes: 59 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[package]
name = "aftman"
description = "Aftman is a command line toolchain manager"
version = "0.2.3"
version = "0.2.5"
rust-version = "1.58.0"
license = "MIT"
edition = "2021"
repository = "https://github.com/LPGhatguy/aftman"
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace]
members = ["test-util"]

[dependencies]
anyhow = "1.0.43"
Expand All @@ -23,6 +25,7 @@ semver = { version = "1.0.4", features = ["serde"] }
serde = { version = "1.0.129", features = ["derive"] }
serde_json = "1.0.67"
structopt = "0.3.22"
tempfile = "3.3.0"
toml = "0.5.8"
toml_edit = "0.14.4"
zip = "0.5.13"
Expand All @@ -36,5 +39,7 @@ tokio = { version = "1.18.2", features = ["macros", "sync", "process"] }
signal-hook = "0.3.14"

[dev-dependencies]
test-util = { path = "test-util" }
tempfile = "3.3.0"
serde_json = "1.0.66"
insta = "1.15.0"
35 changes: 13 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,23 @@ $ cat aftman.toml
rojo = "rojo-rbx/rojo@7.1.0"
```

## Installation
You can install Aftman from crates.io using Rust 1.58.0 or newer:
## Supported Platforms
Aftman supports:

```bash
cargo install aftman
```
- Windows (x86, x86-64)
- macOS (x86-64, AArch64)
- Linux (x86, x86-64)

## Installation
You can install Aftman by downloading a pre-built binary for your platform from Aftman's [GitHub Releases Page](https://github.com/LPGhatguy/aftman/releases).

On Windows, you should then run
Once you have the release unzipped, run:

```bash
aftman self-install
./aftman self-install
```

This will install Aftman to its own bin directory and update the `PATH` environment variable for you.

On other platforms, you'll need to add Aftman's bin directory to your system `PATH`:

- On Windows: `%USERPROFILE%\.aftman\bin`
- On Linux or macOS: `~/.aftman/bin`
This will install Aftman to its own bin directory and update your system's `PATH` environment variable for you.

## Getting Started
To create a new `aftman.toml` file in your current directory, run
Expand Down Expand Up @@ -71,13 +69,6 @@ To install all tools listed by your `aftman.toml` files, run
aftman install
```

## Supported Platforms
Aftman supports:

- Windows (x86, x86-64)
- macOS (x86-64, AArch64)
- Linux (x86, x86-64)

## Subcommands
For detailed help information, run `aftman --help`.

Expand Down Expand Up @@ -164,7 +155,7 @@ I'm hoping to fix some of the core design mistakes I made in Foreman and also ta
* **Change model to no longer trust-by-default.** Aftman prompts before downloading new tools. ([Roblox/foreman#16]).
* **Better strategy for storing executables.** ([Roblox/foreman#11])
* **Better heuristics for picking the right artifacts for your platform.** Aftman uses your Compiler, OS, architecture, and will eventually support custom patterns. ([Roblox/foreman#18])
* **Proper error handling.** Unlike Foreman, which uses `Result::unwrap` liberally, Aftman has good error hygeine with helpful context attached.
* **Proper error handling.** Unlike Foreman, which uses `Result::unwrap` liberally, Aftman has good error hygiene with helpful context attached.
* **Less Roblox-angled.** Aftman does not market itself as being for Roblox development. It is a generally useful tool that can install all sorts of CLI tools.

[Foreman]: https://github.com/Roblox/foreman
Expand All @@ -173,4 +164,4 @@ I'm hoping to fix some of the core design mistakes I made in Foreman and also ta
[Roblox/foreman#18]: https://github.com/Roblox/foreman/issues/18

## License
Aftman is available under the terms of the MIT license. See <https://opensource.org/licenses/MIT> or [LICENSE](LICENSE) for details.
Aftman is available under the terms of the MIT license. See <https://opensource.org/licenses/MIT> or [LICENSE](LICENSE) for details.
6 changes: 3 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Args {
Subcommand::Add(sub) => sub.run(tools),
Subcommand::Install(sub) => sub.run(tools),
Subcommand::Trust(sub) => sub.run(home),
Subcommand::SelfInstall(sub) => sub.run(tools),
Subcommand::SelfInstall(sub) => sub.run(home, tools),

Subcommand::List(_) => bail!("This command is not yet implemented."),
Subcommand::Update(_) => bail!("This command is not yet implemented."),
Expand Down Expand Up @@ -163,10 +163,10 @@ pub struct SelfUpdateSubcommand {}
pub struct SelfInstallSubcommand {}

impl SelfInstallSubcommand {
pub fn run(self, tools: ToolStorage) -> anyhow::Result<()> {
pub fn run(self, home: &Home, tools: ToolStorage) -> anyhow::Result<()> {
tools.update_links()?;

if crate::system_path::add(&tools.bin_dir)? {
if crate::system_path::add(&home)? {
log::info!(
"Added ~/.aftman/bin to your PATH. Restart your terminal for this to take effect."
);
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

use std::io::{self, BufWriter, Write};
use std::path::Path;

Expand All @@ -17,6 +19,7 @@ pub fn write_only_new(path: &Path, contents: &str) -> anyhow::Result<()> {
};

file.write_all(contents.as_bytes())?;
file.into_inner()?;

Ok(())
}
Expand All @@ -34,6 +37,7 @@ pub fn write_if_not_exists(path: &Path, contents: &str) -> anyhow::Result<()> {
};

file.write_all(contents.as_bytes())?;
file.into_inner()?;

Ok(())
}
10 changes: 10 additions & 0 deletions src/dirs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::env;
use std::path::PathBuf;

pub fn home_dir() -> Option<PathBuf> {
if let Ok(home) = env::var("AFTMAN_HOME") {
return Some(PathBuf::from(home));
}

dirs::home_dir()
}
37 changes: 33 additions & 4 deletions src/home.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::env;
use std::path::{Path, PathBuf};
use std::path::{Path, PathBuf, MAIN_SEPARATOR};
use std::sync::Arc;

use anyhow::format_err;

use crate::dirs::home_dir;

/// Defines the root that everything else in Aftman is stored relative to.
///
/// This type encourages good organization, helps us behave predictably, and
Expand All @@ -19,14 +21,14 @@ pub struct Home {

impl Home {
pub fn from_env() -> anyhow::Result<Self> {
// Users can override the Aftman home directory via the AFTMAN_HOME
// Users can override the Aftman home directory via the AFTMAN_ROOT
// environment variable.
if let Ok(var) = env::var("AFTMAN_HOME") {
if let Ok(var) = env::var("AFTMAN_ROOT") {
return Ok(Self::from_path(var));
}

let mut path =
dirs::home_dir().ok_or_else(|| format_err!("Home directory could not be found."))?;
home_dir().ok_or_else(|| format_err!("Home directory could not be found."))?;

path.push(".aftman");

Expand Down Expand Up @@ -55,4 +57,31 @@ impl Home {
pub fn path(&self) -> &Path {
self.path.as_ref()
}

pub fn path_str(&self) -> String {
rehomeify(&self.path)
}

pub fn bin_dir(&self) -> PathBuf {
self.path.join("bin")
}

pub fn bin_dir_str(&self) -> String {
rehomeify(&self.bin_dir())
}
}

/// Returns a human-friendly version of `path`, re-substituting `$HOME` if
/// it is present in the path.
fn rehomeify(path: &Path) -> String {
if let Ok(home) = env::var("HOME") {
let prefix = Path::new(&home);
if let Ok(stripped) = path.strip_prefix(prefix) {
let rest = stripped.to_str().unwrap();

return format!("$HOME{MAIN_SEPARATOR}{rest}");
}
}

path.to_str().unwrap().to_owned()
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod auth;
mod cli;
mod config;
mod dirs;
mod home;
mod ident;
mod manifest;
Expand Down
Loading

0 comments on commit 884f848

Please sign in to comment.