From 1b42869e3f5a12d47bde1eea4d3165c3b81966f6 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Mon, 10 Jun 2024 09:53:43 -0400 Subject: [PATCH] show hidden flag implemented --- qdls/Program.cs | 18 +++++++++--------- qdls/Util.cs | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) 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 {