feature: add gh + cheat sheet
authorOnwuzor Victor <onwuzorvictor@outlook.com>
Sun, 9 May 2021 15:55:30 +0000 (16:55 +0100)
committerAJ ONeal <aj@therootcompany.com>
Sun, 14 Nov 2021 08:41:25 +0000 (08:41 +0000)
gh/README.md [new file with mode: 0644]
gh/install.ps1 [new file with mode: 0644]
gh/install.sh [new file with mode: 0644]
gh/releases.js [new file with mode: 0644]

diff --git a/gh/README.md b/gh/README.md
new file mode 100644 (file)
index 0000000..3ac08de
--- /dev/null
@@ -0,0 +1,31 @@
+---
+title: GitHub CLI
+homepage: https://github.com/cli/cli
+tagline: |
+  `gh` is GitHub on the command line.
+---
+
+## Updating and Switch versions
+
+```bash
+webi gh
+```
+
+## Cheat Sheet
+
+> `gh` doesn't exist and this text should have been replaced. It doesn't do
+> anything, but what it does is useful because it is; everybody knows it.
+
+To run gh:
+
+```bash
+gh
+```
+
+### Add Baz Highlighting
+
+To run gh with both bar and baz highlighting turned on:
+
+```bash
+gh --bar=baz
+```
diff --git a/gh/install.ps1 b/gh/install.ps1
new file mode 100644 (file)
index 0000000..9b70e84
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/env pwsh
+
+##############
+# Install gh #
+##############
+
+# Every package should define these variables
+$pkg_cmd_name = "gh"
+
+$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\gh.exe"
+$pkg_dst = "$pkg_dst_cmd"
+
+$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\gh-v$Env:WEBI_VERSION\bin\gh.exe"
+$pkg_src_bin = "$Env:USERPROFILE\.local\opt\gh-v$Env:WEBI_VERSION\bin"
+$pkg_src_dir = "$Env:USERPROFILE\.local\opt\gh-v$Env:WEBI_VERSION"
+$pkg_src = "$pkg_src_cmd"
+
+$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
+{
+    # TODO: arch detection
+    echo "Downloading gh from $Env:WEBI_PKG_URL to $pkg_download"
+    & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
+    & move "$pkg_download.part" "$pkg_download"
+}
+
+IF (!(Test-Path -Path "$pkg_src_cmd"))
+{
+    echo "Installing gh"
+
+    # TODO: create package-specific temp directory
+    # Enter tmp
+    pushd .local\tmp
+
+        # Remove any leftover tmp cruft
+        Remove-Item -Path ".\gh-v*" -Recurse -ErrorAction Ignore
+        Remove-Item -Path ".\gh.exe" -Recurse -ErrorAction Ignore
+
+        # NOTE: DELETE THIS COMMENT IF NOT USED
+        # Move single binary into root of temporary folder
+        #& move "$pkg_download" "gh.exe"
+
+        # Unpack archive file into this temporary directory
+        # Windows BSD-tar handles zip. Imagine that.
+        echo "Unpacking $pkg_download"
+        & tar xf "$pkg_download"
+
+        # Settle unpacked archive into place
+        echo "Install Location: $pkg_src_cmd"
+        New-Item "$pkg_src_bin" -ItemType Directory -Force | out-null
+        Move-Item -Path ".\bin\gh.exe" -Destination "$pkg_src_bin"
+
+    # Exit tmp
+    popd
+}
+
+echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
+Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | out-null
+Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
diff --git a/gh/install.sh b/gh/install.sh
new file mode 100644 (file)
index 0000000..de0d78a
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+function __init_gh() {
+    set -e
+    set -u
+
+    ##############
+    # Install gh #
+    ##############
+
+    # Every package should define these 6 variables
+    pkg_cmd_name="gh"
+
+    pkg_dst_cmd="$HOME/.local/bin/gh"
+    pkg_dst="$pkg_dst_cmd"
+
+    pkg_src_cmd="$HOME/.local/opt/gh-v$WEBI_VERSION/bin/gh"
+    pkg_src_dir="$HOME/.local/opt/gh-v$WEBI_VERSION"
+    pkg_src="$pkg_src_cmd"
+
+    # pkg_install must be defined by every package
+    pkg_install() {
+        # ~/.local/opt/gh-v0.99.9/bin
+        mkdir -p "$(dirname $pkg_src_cmd)"
+
+        # mv ./gh-*/gh ~/.local/opt/gh-v0.99.9/bin/gh
+        mv ./"$pkg_cmd_name"*/bin/gh "$pkg_src_cmd"
+    }
+
+    # pkg_get_current_version is recommended, but (soon) not required
+    pkg_get_current_version() {
+        # 'gh --version' has output in this format:
+        #       gh 0.99.9 (rev abcdef0123)
+        # This trims it down to just the version number:
+        #       0.99.9
+        echo $(gh --version 2> /dev/null | head -n 1 | cut -d ' ' -f 2)
+    }
+
+}
+
+__init_gh
diff --git a/gh/releases.js b/gh/releases.js
new file mode 100644 (file)
index 0000000..816fe55
--- /dev/null
@@ -0,0 +1,20 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'cli';
+var repo = 'cli';
+
+module.exports = function (request) {
+  return github(request, owner, repo).then(function (all) {
+    return all;
+  });
+};
+
+if (module === require.main) {
+  module.exports(require('@root/request')).then(function (all) {
+    all = require('../_webi/normalize.js')(all);
+    // just select the first 5 for demonstration
+    all.releases = all.releases.slice(0, 5);
+    console.info(JSON.stringify(all, null, 2));
+  });
+}