Skip to content

Commit

Permalink
Set up a simple CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
stepchowfun committed Jul 8, 2019
0 parents commit 380ae73
Show file tree
Hide file tree
Showing 12 changed files with 572 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Keep this file in sync with `.ignore`.
artifacts/
release/
target/
4 changes: 4 additions & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Keep this file in sync with `.gitignore`.
artifacts/
release/
target/
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: generic
services: docker
install:
- |
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
echo "$DOCKER_HUB_PASSWORD" |
docker login --username stephanmisc --password-stdin
fi
curl https://raw.githubusercontent.com/stepchowfun/toast/master/install.sh -LSfs |
VERSION=0.28.0 sh
script:
- |
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
WRITE_REMOTE_CACHE=true
else
WRITE_REMOTE_CACHE=false
fi
toast build test lint run \
--repo stephanmisc/toast \
--read-remote-cache true \
--write-remote-cache "$WRITE_REMOTE_CACHE"
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.0] - 2019-07-07

### Added
- Initial release.
174 changes: 174 additions & 0 deletions Cargo.lock

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

19 changes: 19 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "gram"
version = "0.0.0"
authors = ["Stephan Boyer <[email protected]>"]
edition = "2018"
description = "A high-level programming language."
license = "MIT"
documentation = "https://github.com/gramlang/gram"
homepage = "https://github.com/gramlang/gram"
repository = "https://github.com/gramlang/gram"
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dependencies.clap]
version = "2"
features = ["wrap_help"]
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Stephan Boyer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# The Gram Programming Language

[![Build Status](https://travis-ci.org/gramlang/gram.svg?branch=master)](https://travis-ci.org/gramlang/gram)

[Gram](https://www.gram.org) is a high-level programming language.

## Installation

### Easy installation

If you are running macOS or a GNU-based Linux on an x86-64 CPU, you can install Gram with this command:

```sh
curl https://raw.githubusercontent.com/gramlang/gram/master/install.sh -LSfs | sh
```

The same command can be used again to update Gram to the latest version.

**NOTE:** Piping `curl` to `sh` is dangerous since the server might be compromised. If you're concerned about this, you can download and inspect the installation script or choose one of the other installation methods.

#### Customizing the installation

The installation script supports the following environment variables:

- `VERSION=x.y.z` (defaults to the latest version)
- `PREFIX=/path/to/install` (defaults to `/usr/local/bin`)

For example, the following will install Gram into the working directory:

```sh
curl https://raw.githubusercontent.com/gramlang/gram/master/install.sh -LSfs | PREFIX=. sh
```

### Manual installation

The [releases page](https://github.com/gramlang/gram/releases) has precompiled binaries for macOS or Linux systems running on an x86-64 CPU. You can download one of them and place it in a directory listed in your [`PATH`](https://en.wikipedia.org/wiki/PATH_\(variable\)).

### Installation with Cargo

If you have [Cargo](https://doc.rust-lang.org/cargo/), you can install Gram as follows:

```sh
cargo install gram
```

You can run that command with `--force` to update an existing installation.
72 changes: 72 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env sh

# Usage examples:
# ./install.sh
# VERSION=x.y.z ./install.sh
# PREFIX=/usr/local/bin ./install.sh

# We wrap everything in parentheses for two reasons:
# 1. To prevent the shell from executing only a prefix of the script if the download is interrupted
# 2. To ensure that any working directory changes with `cd` are local to this script and don't
# affect the calling user's shell
(
# Where the binary will be installed
DESTINATION="${PREFIX:-/usr/local/bin}/gram"

# Which version to download
RELEASE="v${VERSION:-0.0.0}"

# Determine which binary to download.
FILENAME=''
if uname -a | grep -qi 'x86_64.*GNU/Linux'; then
echo 'x86_64 GNU/Linux detected.'
FILENAME=gram-x86_64-unknown-linux-gnu
fi
if uname -a | grep -qi 'Darwin.*x86_64'; then
echo 'macOS detected.'
FILENAME=gram-x86_64-apple-darwin
fi

# Find a temporary location for the binary.
TEMPDIR=$(mktemp -d /tmp/gram.XXXXXXXX)

# This is a helper function to clean up and fail.
fail() {
echo "$1" >&2
cd "$TEMPDIR/.." || exit 1
rm -rf "$TEMPDIR"
exit 1
}

# Enter the temporary directory.
cd "$TEMPDIR" || fail "Unable to access the temporary directory $TEMPDIR."

# Fail if there is no pre-built binary for this platform.
if [ -z "$FILENAME" ]; then
fail 'Unfortunately, there is no pre-built binary for this platform.'
fi

# Download the binary.
if ! curl "https://github.com/gramlang/gram/releases/download/$RELEASE/$FILENAME" \
-o "$FILENAME" -LSf; then
fail 'There was an error downloading the binary.'
fi

# Make it executable.
if ! chmod a+rx "$FILENAME"; then
fail 'There was an error setting the permissions for the binary.'
fi

# Install it at the requested destination.
# shellcheck disable=SC2024
mv "$FILENAME" "$DESTINATION" 2> /dev/null ||
sudo mv "$FILENAME" "$DESTINATION" < /dev/tty ||
fail "Unable to install the binary at $DESTINATION."

# Remove the temporary directory.
cd ..
rm -rf "$TEMPDIR"

# Let the user know it worked.
echo "$("$DESTINATION" --version) is now installed."
)
Loading

0 comments on commit 380ae73

Please sign in to comment.