aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODOs.org1
-rwxr-xr-xcli43
-rwxr-xr-xwebsite.bats11
-rwxr-xr-xwebsite.pl63
4 files changed, 75 insertions, 43 deletions
diff --git a/TODOs.org b/TODOs.org
index d5071a5..8bb3f26 100644
--- a/TODOs.org
+++ b/TODOs.org
@@ -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?
diff --git a/cli b/cli
deleted file mode 100755
index a2f8a44..0000000
--- a/cli
+++ /dev/null
@@ -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)
+
+