diff --git a/qdls/Program.cs b/qdls/Program.cs index 9dd3bb1..1a83465 100644 --- a/qdls/Program.cs +++ b/qdls/Program.cs @@ -1,15 +1,14 @@  using Qdls; -// collect args; no args becomes working directory -string[] arguments; -if(args.Length == 0) - arguments = ["."]; -else - arguments = args; +// collect args and consume flags +List arguments = args.ToList(); -// flags -bool showHidden = false; +bool showHidden = Util.CheckFlag(arguments, "-a", "--all", "-A"); + +// default to "." if no target args +if(arguments.Count == 0) + arguments = ["."]; // run on targets foreach(var arg in arguments) { @@ -21,6 +20,7 @@ foreach(var arg in arguments) { // fetch children var children = Directory.GetFileSystemEntries(arg); + // exclude hidden files where applicable if(!showHidden) { children = children.Where(f => !Util.IsHidden(f)).ToArray(); } // state vars @@ -37,7 +37,7 @@ foreach(var arg in arguments) { foreach(var child in children) { var name = Path.GetFileName(child); - // skip or format hidden files + // format hidden files if(Util.IsHidden(child)) buffer += Format.Hidden; diff --git a/qdls/Util.cs b/qdls/Util.cs index 6b3200a..103f34c 100644 --- a/qdls/Util.cs +++ b/qdls/Util.cs @@ -11,6 +11,11 @@ public static class Util { ( File.GetAttributes(path) & FileAttributes.Hidden ) == FileAttributes.Hidden; } + public static bool CheckFlag(List args, params string[] forms) { + var found = args.RemoveAll(forms.Contains); + return found > 0; + } + } public static class Format {