summaryrefslogtreecommitdiff
path: root/uri
diff options
context:
space:
mode:
authorNick Shipp <nick@shipp.ninja>2017-06-03 01:33:15 -0400
committerNick Shipp <nick@shipp.ninja>2017-06-03 01:33:15 -0400
commit40f17d1f4bd03c48cb89a6e70e9cd7a3259334c6 (patch)
tree5984140fe779d76aac734bf0cc1474c2a03bddce /uri
Initial commitHEADmaster
Diffstat (limited to 'uri')
-rwxr-xr-xuri52
1 files changed, 52 insertions, 0 deletions
diff --git a/uri b/uri
new file mode 100755
index 0000000..9f77bbf
--- /dev/null
+++ b/uri
@@ -0,0 +1,52 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+use URI;
+use URI::QueryParam;
+use feature 'say';
+
+die "Usage: $0 COMMAND [URIs]" unless @ARGV >= 1;
+
+my $command = shift;
+
+sub make_uri {
+ my $uri = shift;
+ my @opts = map { s/^--//; [split /=/, $_, 2] } @ARGV;
+ for (@opts) {
+ my ($k, $v) = @$_;
+ if ($k =~ /^query-param-(.+)$/) {
+ $uri->query_param($1 => $v);
+ } else {
+ $uri->$k($v);
+ }
+ }
+ say $uri->as_string;
+}
+
+sub take_it {
+ chomp;
+ my $uri = URI->new($_);
+ die "Invalid command for $_: $command" unless $uri->can($command);
+ my $val = $uri->$command;
+
+ if (defined $val) {
+ exit !$val if $val =~ /^[01]$/;
+ say $val;
+ } else {
+ say "undefined";
+ exit 1;
+ }
+}
+
+if ($command eq 'create') {
+ make_uri(URI->new);
+} elsif ($command eq 'change') {
+ make_uri(URI->new($_)) while <STDIN>;
+} else {
+ if (@ARGV) {
+ take_it for @ARGV;
+ } else {
+ take_it while <STDIN>;
+ }
+}