diff options
author | EuAndreh <eu@euandre.org> | 2018-12-29 09:38:39 -0200 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2018-12-29 09:38:39 -0200 |
commit | 9934dd7fae3b881690df158b3f15a5f96c3aed72 (patch) | |
tree | e80ed6deab9006c8b5a20fdca8a912fade9c2746 | |
parent | Add initial Racket CLI for handling scripts. (diff) | |
download | euandre.org-9934dd7fae3b881690df158b3f15a5f96c3aed72.tar.gz euandre.org-9934dd7fae3b881690df158b3f15a5f96c3aed72.tar.xz |
WIP: Use Perl instead of Racket for CLI.
Diffstat (limited to '')
-rw-r--r-- | TODOs.org | 1 | ||||
-rwxr-xr-x | cli | 43 | ||||
-rwxr-xr-x | website.bats | 11 | ||||
-rwxr-xr-x | website.pl | 63 |
4 files changed, 75 insertions, 43 deletions
@@ -7,6 +7,7 @@ https://joelkuiper.eu/spellcheck_emacs https://jaspervdj.be/hakyll/tutorials/using-teasers-in-hakyll.html * CLI ** Print usage when no subcommand is provided +** Add completion * CI ** Improvements *** Use NixOS instead of Debian? @@ -1,43 +0,0 @@ -#!/usr/bin/env racket -#lang racket - -(define pastebin-verbose? (make-parameter #false)) -(define pastebin-title (make-parameter "")) -(define slide-verbose? (make-parameter #false)) - -(define subcommand - (command-line - #:program "website-cli" - #:args (subcommand . subcommand-options) - (match subcommand - ["pastebin" - (command-line - #:program "website-cli pastebin" - #:argv subcommand-options - #:multi - [("-v" "--verbose") "dunno" (pastebin-verbose? #true)] - [("-t" "--title") title "The title of the pastebin, will be slugified for creating the filename." (pastebin-title title)])] - ["slide" - (command-line - #:program "website-cli slide" - #:argv subcommand-options - #:usage-help - "woeifj ijfe" - #:multi - [("-v" "--verbose") "Turn on verbose mode" (slide-verbose? #false)] - #:help-labels - "oefijeifjeijfiejfijeij ijij" - #:ps "ps")] - [_ - (printf "Invalid subcommand: ~a\n" subcommand) - (exit 1)]) - subcommand)) - -(define out - (match subcommand - ["pastebin" - (system "./pastebin/new.sh")] - ["slide" - (system "./slides/new.sh")])) - -(exit (if out 0 1)) diff --git a/website.bats b/website.bats new file mode 100755 index 0000000..c9319ed --- /dev/null +++ b/website.bats @@ -0,0 +1,11 @@ +#!/usr/bin/env bats + +# @test "Help: show short usage when no subcommand is given." { +# run ./cli.pl +# [[ "$status" -eq 1 ]] +# } + +# print short usage +# show manpage +# create pastebin +# create a slide diff --git a/website.pl b/website.pl new file mode 100755 index 0000000..cb81ff3 --- /dev/null +++ b/website.pl @@ -0,0 +1,63 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i perl -p perl less --pure + +=head1 NAME + +cli.pl - Using GetOpt::Long and Pod::Usage + +=head1 SYNOPSIS + +sample [options] [file ...] + + Options: + --help brief help message + --man full documentation + +=head1 OPTIONS + +=over 4 + +=item B<-h, --help> + +Print a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=back + +=head1 DESCRIPTION + +B<This program> will read the given input file(s) and do something +useful with the contents thereof. + +=cut + +use strict; +use warnings; +use Getopt::Long qw(:config no_ignore_case bundling auto_help auto_version); +use Pod::Usage qw(pod2usage); + +my $help = 0; +my $title = ''; +GetOptions( + "t|title=s" => \$title, + 'help|h|?' => \$help +) or pod2usage(-verbose => 1); +pod2usage( + -verbose => 2, + -exitval => 0 +) if $help || (defined $ARGV[0] and $ARGV[0] eq "help"); + +## If no arguments were given, then allow STDIN to be used only +## if it's not connected to a terminal (otherwise print usage) +pod2usage("$0: No files given.") if ((@ARGV == 0) && (-t STDIN)); + +print `fd sh`; +print `find . -type f -name '*sh*'`; + + +# FIXME: add tests (inline + bats) + + |