Skip to content

Commit

Permalink
feat(cli): add --quiet cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Jan 3, 2022
1 parent c206598 commit d03c84a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Husky/Cli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ private static string[] HandleHighPriorityArgs(string[] args)
if (args.Contains("--verbose") || args.Contains("-v"))
Logger.Logger.Verbose = true;

return args.Where(x => x != "--verbose" && x != "-v" && x != "--no-color").ToArray();
if (args.Contains("--quiet") || args.Contains("-q"))
Logger.Logger.Quiet = true;

var exclude = new[] { "--no-color", "--verbose", "--quiet", "-v", "-q" };
return args.Where(x => !exclude.Contains(x)).ToArray();
}

private static async ValueTask<int> RunCommand(string cmd, IReadOnlyList<string> args)
{
var ac = args.Count;
return cmd switch
{
"--no-color" or "-v" or "--verbose" => 0,
"--help" or "-h" or "-?" => Help(),
"--version" or "-V" => CliActions.Version(),
"install" when ac > 1 && !args[1].StartsWith("-") => await CliActions.Install(args[1]),
Expand Down Expand Up @@ -114,8 +117,9 @@ private static int Help()
Options:
-h | --help|-? Show help information
-V | --version Show version information
-v | --verbose Show verbose output
-c | --no-color Disable color output
-v | --verbose Show verbose output (default: false)
-c | --no-color Disable color output (default: false)
-q | --quiet Disable [Husky] console output (default: false)
Commands:
husky install [dir] (default: .husky) Install Husky hooks
Expand Down
2 changes: 2 additions & 0 deletions src/Husky/CliActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,6 @@ public static async Task<int> Exec(string path, string[] args)

return 1;
}


}
3 changes: 3 additions & 0 deletions src/Husky/Logger/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public static class Logger
public static bool Verbose = false;
public static bool Colors = true;
public static bool Vt100Colors = false;
public static bool Quiet = false;

private static void Write(string message, ConsoleColor? color = null)
{
Expand Down Expand Up @@ -33,6 +34,7 @@ private static void WriteLine(string message, ConsoleColor? color = null)

public static void Husky(this string message, ConsoleColor? color = null)
{
if (Quiet) return;
Write("[Husky] ", ConsoleColor.Cyan);
WriteLine($"{message}", color);
}
Expand All @@ -44,6 +46,7 @@ public static void Log(this string message, ConsoleColor? color = null)

public static void Hr(int count = 50, ConsoleColor? color = ConsoleColor.DarkGray)
{
if (Quiet) return;
WriteLine(new string('-', count), color);
}

Expand Down

0 comments on commit d03c84a

Please sign in to comment.