From 69a715251d69877b3b2efc77ac6b37f7c31df4b3 Mon Sep 17 00:00:00 2001 From: Valentin Reis Date: Thu, 13 Dec 2018 10:29:01 -0600 Subject: [PATCH] [feature] Added some minor dev workflow tools. See file ".Makefile". - shell completions - readme generation --- .Makefile | 22 +++++++++++++++++++ .README.md | 44 ++++++++++++++++++++++++++++++++++++++ README.md | 26 +++++++++++++++++----- completions/bash/argotk.sh | 14 ++++++++++++ completions/zsh/_argotk.hs | 32 +++++++++++++++++++++++++++ default.nix | 5 +++++ 6 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 .Makefile create mode 100644 .README.md create mode 100644 completions/bash/argotk.sh create mode 100644 completions/zsh/_argotk.hs diff --git a/.Makefile b/.Makefile new file mode 100644 index 0000000..0b7646b --- /dev/null +++ b/.Makefile @@ -0,0 +1,22 @@ +#This makefile only contains development workflow rules. +.PHONY: all +all: generate-completions README.md + +.PHONY: generate-completions +generate-completions: completions/zsh/_argotk.hs completions/bash/argotk.sh + +completions/zsh/_argotk.hs: argotk.hs default.nix + nix-shell -A dev-test --run "bash -c './argotk.hs --zsh-completion-script ./argotk.hs > completions/zsh/_argotk.hs'" + +completions/bash/argotk.sh: argotk.hs default.nix + nix-shell -A dev-test --run "bash -c './argotk.hs --bash-completion-script ./argotk.hs > completions/bash/argotk.sh'" + +README.md: .README.md argotk.hs default.nix + nix-shell -A dev-test --run "pandoc --filter `which panpipe` .README.md -o README.md" + +README.html: README.md + nix-shell -A dev-test --run "pandoc README.md -o README.html" + +.PHONY:clean +clean: + rm README.html diff --git a/.README.md b/.README.md new file mode 100644 index 0000000..9cd0821 --- /dev/null +++ b/.README.md @@ -0,0 +1,44 @@ +#### integration testing + +This repository contains integration tests that validate the argo stack. + +It leverages the argopkgs repo, but overrides some sources in it with +their master branch counterparts. see file `default.nix` for details. + +The real intended usage is to override (some of) the source(s) with WIP +version(s), as part of development or continuous integration. This gitlab CI +snippets shows how to do this on a nix-enabled runner: + +```{.yml} +integration.test: + stage: test + script: + - BUILD=$PWD + - git clone https://xgitlab.cels.anl.gov/argo/argotest.git + - cd argotest + - nix-shell -A test --run "./argotk.hs helloworld" --arg nrm-src ../. + artifacts: + paths: + - argotest/cmd_err.log + - argotest/cmd_out.log + - argotest/daemon_out.log + - argotest/daemon_out.log + - argotest/nrm.log + - argotest/time.log + expire_in: 1 week + except: + - /^wip\/.*/ + - /^WIP\/.*/ + tags: + - integration +``` + +Standalone usage: example with the nrm source in `../`. +```{.bash} +nix-shell -A test --arg nrm-src ../nrm +nix-shell $ ./argotk.hs --help +``` +Output: +```{.txt pipe="sh"} +root/argotk.hs --help +``` diff --git a/README.md b/README.md index df9c6df..5be1b80 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ It leverages the argopkgs repo, but overrides some sources in it with their master branch counterparts. see file `default.nix` for details. The real intended usage is to override (some of) the source(s) with WIP -version(s), as part of development or continuous integration. This gitlab CI -snippets shows how to do this on a nix-enabled runner: +version(s), as part of development or continuous integration. This +gitlab CI snippets shows how to do this on a nix-enabled runner: -```{.yml} +``` {.yml} integration.test: stage: test script: @@ -34,7 +34,23 @@ integration.test: ``` Standalone usage: example with the nrm source in `../`. -``` + +``` {.bash} nix-shell -A test --arg nrm-src ../nrm -./integration.hs +nix-shell $ ./argotk.hs --help +``` + +Output: + +``` {.txt} +Usage: argotk.hs COMMAND + +Available options: + COMMAND Target for the greeting + -h,--help Show this help text + +Available commands: + clean + daemon + helloworld ``` diff --git a/completions/bash/argotk.sh b/completions/bash/argotk.sh new file mode 100644 index 0000000..b5fec2e --- /dev/null +++ b/completions/bash/argotk.sh @@ -0,0 +1,14 @@ +_argotk.hs() +{ + local CMDLINE + local IFS=$'\n' + CMDLINE=(--bash-completion-index $COMP_CWORD) + + for arg in ${COMP_WORDS[@]}; do + CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg) + done + + COMPREPLY=( $(./argotk.hs "${CMDLINE[@]}") ) +} + +complete -o filenames -F _argotk.hs argotk.hs diff --git a/completions/zsh/_argotk.hs b/completions/zsh/_argotk.hs new file mode 100644 index 0000000..a0c5d7c --- /dev/null +++ b/completions/zsh/_argotk.hs @@ -0,0 +1,32 @@ +#compdef argotk.hs + +local request +local completions +local word +local index=$((CURRENT - 1)) + +request=(--bash-completion-enriched --bash-completion-index $index) +for arg in ${words[@]}; do + request=(${request[@]} --bash-completion-word $arg) +done + +IFS=$'\n' completions=($( ./argotk.hs "${request[@]}" )) + +for word in $completions; do + local -a parts + + # Split the line at a tab if there is one. + IFS=$'\t' parts=($( echo $word )) + + if [[ -n $parts[2] ]]; then + if [[ $word[1] == "-" ]]; then + local desc=("$parts[1] ($parts[2])") + compadd -d desc -- $parts[1] + else + local desc=($(print -f "%-019s -- %s" $parts[1] $parts[2])) + compadd -l -d desc -- $parts[1] + fi + else + compadd -f -- $word + fi +done diff --git a/default.nix b/default.nix index 6e0364c..978cf68 100644 --- a/default.nix +++ b/default.nix @@ -39,6 +39,7 @@ in rec p.unix p.system-filepath p.async + (pkgs.haskell.lib.doJailbreak p.panpipe) ])) containers hpkgs.hdevtools @@ -50,6 +51,10 @@ in rec }; test = pkgs.stdenv.mkDerivation rec { + shellHook = '' + source completions/bash/argotk.sh + echo "Installed bash completions." + ''; name = "env"; env = pkgs.buildEnv { name = name; paths = buildInputs; }; buildInputs = [ -- 2.26.2