show hidden flag implemented

This commit is contained in:
Valerie Wolfe 2024-06-10 09:53:43 -04:00
parent 6f61a98ebc
commit 1b42869e3f
2 changed files with 14 additions and 9 deletions

View file

@ -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<string> 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;

View file

@ -11,6 +11,11 @@ public static class Util {
( File.GetAttributes(path) & FileAttributes.Hidden ) == FileAttributes.Hidden;
}
public static bool CheckFlag(List<String> args, params string[] forms) {
var found = args.RemoveAll(forms.Contains);
return found > 0;
}
}
public static class Format {