Skip to content

Commit

Permalink
feat(cli): install man pages (gakonst#523)
Browse files Browse the repository at this point in the history
* man release

* foundryup support man dir, fix clap name attribute and add clap version attribute

* keep .gz extension so man knows
  • Loading branch information
devanoneth authored Jan 20, 2022
1 parent 940c942 commit f3e1800
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ jobs:
fi
shell: bash

- name: Build man page
id: man
if: ${{ matrix.job.platform == 'linux' }}
env:
PLATFORM_NAME: ${{ matrix.job.platform }}
TARGET: ${{ matrix.job.target }}
run: |
sudo apt-get -y install help2man
help2man -N ./target/${TARGET}/release/forge > forge.1
help2man -N ./target/${TARGET}/release/cast > cast.1
gzip forge.1
gzip cast.1
tar -czvf "foundry_man_${TAG_NAME}.tar.gz" forge.1.gz cast.1.gz
echo "::set-output name=foundry_man::foundry_man_${TAG_NAME}.tar.gz"
shell: bash

- name: Build changelog
id: build_changelog
if: ${{ env.TAG_NAME != 'nightly' }}
Expand Down Expand Up @@ -124,4 +140,6 @@ jobs:
tag_name: ${{ env.TAG_NAME }}
prerelease: ${{ env.TAG_NAME == 'nightly' }}
body: ${{ steps.build_changelog.outputs.changelog }}
files: ${{ steps.artifacts.outputs.file_name }}
files: |
${{ steps.artifacts.outputs.file_name }}
${{ steps.man.outputs.foundry_man }}
3 changes: 2 additions & 1 deletion cli/src/opts/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ethers::types::{Address, BlockId, BlockNumber, NameOrAddress, H256};
use super::{ClapChain, EthereumOpts, Wallet};

#[derive(Debug, Subcommand)]
#[clap(name = "cast")]
#[clap(about = "Perform Ethereum RPC calls from the comfort of your command line.")]
pub enum Subcommands {
#[clap(name = "--max-int")]
Expand Down Expand Up @@ -431,6 +430,8 @@ fn parse_slot(s: &str) -> eyre::Result<H256> {
}

#[derive(Debug, Parser)]
#[clap(name = "cast")]
#[clap(version)]
pub struct Opts {
#[clap(subcommand)]
pub sub: Subcommands,
Expand Down
3 changes: 2 additions & 1 deletion cli/src/opts/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use crate::cmd::{
};

#[derive(Debug, Parser)]
#[clap(name = "forge")]
#[clap(version)]
pub struct Opts {
#[clap(subcommand)]
pub sub: Subcommands,
}

#[derive(Debug, Subcommand)]
#[clap(name = "forge")]
#[clap(about = "Build, test, fuzz, formally verify, debug & deploy solidity contracts.")]
#[allow(clippy::large_enum_variant)]
pub enum Subcommands {
Expand Down
33 changes: 29 additions & 4 deletions foundryup/install
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ echo Installing foundryup...

FOUNDRY_DIR=${FOUNDRY_DIR-"$HOME/.foundry"}
FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin"
FOUNDRY_MAN_DIR="$FOUNDRY_DIR/share/man/man1"

FOUNDRYUP='#!/usr/bin/env bash
set -e
FOUNDRY_DIR=${FOUNDRY_DIR-"$HOME/.foundry"}
FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin"
FOUNDRY_MAN_DIR="$FOUNDRY_DIR/share/man/man1"
while [[ $1 ]]; do
case $1 in
Expand Down Expand Up @@ -63,10 +65,14 @@ if [[ "$FOUNDRYUP_REPO" == "gakonst/foundry" && -z "$FOUNDRYUP_BRANCH" ]]; then
fi
# Compute the URL of the release tarball in the Foundry repository.
TARBALL_URL="https://github.com/${FOUNDRYUP_REPO}/releases/download/${FOUNDRYUP_VERSION}/foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.tar.gz"
# Download the release tarball and unpack it into the .foundry bin directory.
curl -L $TARBALL_URL | tar -xvzC $FOUNDRY_BIN_DIR
RELEASE_URL="https://github.com/${FOUNDRYUP_REPO}/releases/download/${FOUNDRYUP_VERSION}/"
BIN_TARBALL_URL="${RELEASE_URL}foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.tar.gz"
MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${FOUNDRYUP_VERSION}.tar.gz"
# Download the binaries tarball and unpack it into the .foundry bin directory.
curl -L $BIN_TARBALL_URL | tar -xvzC $FOUNDRY_BIN_DIR
# Download the man tarball and unpack it into the .foundry man directory.
curl -L $MAN_TARBALL_URL | tar -xvzC $FOUNDRY_MAN_DIR
else
FOUNDRYUP_BRANCH=${FOUNDRYUP_BRANCH-master}
Expand Down Expand Up @@ -97,6 +103,22 @@ else
# Build the repo and install it locally to the .foundry bin directory.
# --root appends /bin to the directory it is given, so we pass FOUNDRY_DIR.
cargo install --path ./cli --bins --locked --force --root $FOUNDRY_DIR
# Try to also manually build and install the man pages
if ! command -v help2man &> /dev/null ; then
# Warning if help2man is not installed
echo "warning: help2man is not installed, so we could not automatically install man entries"
if [[ "$PLATFORM" == "darwin" ]]; then
echo "You may need to install it manually on MacOS via Homebrew (`brew install help2man`)."
elif [[ "$PLATFORM" == "linux" ]]; then
echo "You may need to install it manually using your package manager."
fi
exit 0
fi
help2man -N $FOUNDRY_BIN_DIR/forge > $FOUNDRY_MAN_DIR/forge.1
help2man -N $FOUNDRY_BIN_DIR/cast > $FOUNDRY_MAN_DIR/cast.1
fi'

BINARY="$FOUNDRY_BIN_DIR/foundryup"
Expand All @@ -106,6 +128,9 @@ mkdir -p $FOUNDRY_BIN_DIR
echo "$FOUNDRYUP" > $BINARY
chmod +x $BINARY

# Create the man directory for future man files if it doesn't exist.
mkdir -p $FOUNDRY_MAN_DIR

# Store the correct profile file (i.e. .profile for bash or .zshrc for ZSH).
case $SHELL in
*/zsh)
Expand Down

0 comments on commit f3e1800

Please sign in to comment.