Permalink
Browse files

Scan the entire directory if no files are given

  • Loading branch information...
1 parent b3d2c7d commit 5c004fc193e749d46e8effed7cfe6a343d900115 @tadzik committed Mar 2, 2011
Showing with 28 additions and 2 deletions.
  1. +8 −0 README
  2. +20 −2 dedeprecator
View
8 README
@@ -6,8 +6,16 @@ for a deprecations and warn you about them.
Usage:
+# scan the current directory for deprecations
+$ dedeprecator
+
# scan test.pir for deprecations, using api.yaml
$ dedeprecator test.pir
# scan bar.pir and baz.pir using the alternate api.yaml file
$ dedeprecator --apiyaml /somewhere/else/foo.yaml bar.pir baz.pir
+
+# in case you forgot everything
+$ dedeprecator -h
+# or
+$ dedeprecator --help
View
@@ -2,6 +2,7 @@
INIT {
pir::load_bytecode("YAML/Tiny.pbc");
+ pir::loadlib("os");
}
sub check_pir($file, @regexes) {
@@ -29,7 +30,6 @@ sub MAIN(@ARGS) {
my $name := @ARGS.shift;
my @files;
my $apiyaml := 'api.yaml';
- USAGE($name) unless pir::elements(@ARGS);
# getopt
my $arg;
while pir::elements(@ARGS) {
@@ -68,6 +68,24 @@ sub MAIN(@ARGS) {
}
}
}
+# if no files are given, find all files in the current directory,
+# recursively
+ unless pir::elements(@files) {
+ my $os := pir::new('OS');
+ my @candidates := $os.readdir('.');
+ while pir::elements(@candidates) {
+ my $file := @candidates.shift;
+ # this probably can be written better
+ next if $file ~~ /[^ '.' $] | [^ '..' $]
+ | ['/..' $] | ['/.' $]/;
+ @files.push($file);
+ try { # try is isdir said funny
+ for $os.readdir($file) {
+ @candidates.push("$file/$_");
+ }
+ }
+ }
+ }
# check the given files
for @files -> $f {
if $f ~~ / '.pir' $ / {
@@ -77,7 +95,7 @@ sub MAIN(@ARGS) {
}
sub USAGE($name) {
- say("Usage: $name [--apiyaml <api.yaml file>] <files to check>");
+ say("Usage: $name [--apiyaml <api.yaml file>] [<files to check>]");
pir::exit(1);
}

0 comments on commit 5c004fc

Please sign in to comment.