Skip to content

Commit ecc98ab

Browse files
committed
Merge
2 parents d464e6c + 1ac6f97 commit ecc98ab

5 files changed

Lines changed: 136 additions & 42 deletions

File tree

ColorCat.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.23107.0
4+
VisualStudioVersion = 14.0.24720.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorCat", "ColorCat\ColorCat.csproj", "{022A0482-5B90-426A-862C-8891C6D5DB8C}"
77
EndProject
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
$packageName = 'ColorCat.portable' # name for the package, used in messages
22
$url ="https://github.com/MasterDevs/ColorCat/releases/download/v0.0.4/bin.zip"
33

4-
$installDir = Join-Path $env:AllUsersProfile "$packageName"
5-
Write-Host "Adding `'$installDir`' to the path and the current shell path"
6-
Install-ChocolateyPath "$installDir"
7-
$env:Path = "$($env:Path);$installDir"
4+
$installDir = Join-Path $env:AllUsersProfile "$packageName"
5+
Write-Host "Adding `'$installDir`' to the path and the current shell path"
6+
Install-ChocolateyPath "$installDir"
7+
$env:Path = "$($env:Path);$installDir"
88

9-
Install-ChocolateyZipPackage "$packageName" "$url" "$installDir"
9+
Install-ChocolateyZipPackage "$packageName" "$url" "$installDir"

ColorCat/ColorCatOptions.cs

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,58 @@ namespace ColorCat
88
{
99
public class ColorCatOptions
1010
{
11-
[Option('a', "add", HelpText = "Add a color mapping to the configuration")]
12-
public bool Add { get; set; }
11+
[VerbOption("add", HelpText = "Add a color mapping to the configuration")]
12+
public AddOption Add { get; set; }
1313

14-
[Option('c', "color", HelpText = "When adding a color mapping, the color to use for the mapping. Requires --add to be specified.")]
15-
public ConsoleColor Color { get; set; }
14+
[HelpOption]
15+
[HelpVerbOption]
16+
public string GetUsage(string verb)
17+
{
18+
var help = HelpText.AutoBuild(this, verb);
1619

17-
[Option('i', "ignoreCase", HelpText = "When adding a color mapping, ignore case when executing the mapping. Requires --add to be specified.")]
18-
public bool IgnoreCase { get; set; }
20+
help.AdditionalNewLineAfterOption = true;
1921

20-
[Option('r', "regex", HelpText = "When adding a color mapping, execute mapping as a regular expression instead of a string compare. Requires --add to be specified.")]
21-
public bool IsRegex { get; set; }
22+
switch (verb)
23+
{
24+
case null:
25+
help.AddPreOptionsLine("To colorize the output of another program (such as tail or cat) simply pipe into colorCat");
2226

23-
[ValueList(typeof(List<string>))]
24-
public IList<string> Pattern { get; set; }
27+
help.AddPostOptionsLine(string.Empty);
28+
help.AddPostOptionsLine("For more information on a specific command use --help");
29+
help.AddPostOptionsLine("Example: colorCat add --help");
2530

26-
[HelpOption]
27-
public string GetUsage()
28-
{
29-
var asm = typeof(ColorCatOptions).Assembly;
31+
help.AddPostOptionsLine(string.Empty);
32+
help.AddPostOptionsLine("Basic Usage:");
33+
help.AddPostOptionsLine(" > tail -f myLogFile | colorCat");
34+
35+
help.AddPostOptionsLine(string.Empty);
36+
break;
37+
38+
case "add":
39+
40+
help.AddPostOptionsLine("Valid colors are: ");
41+
foreach (var color in Enum.GetNames(typeof(ConsoleColor)))
42+
{
43+
help.AddPostOptionsLine($" {color}");
44+
}
45+
46+
help.AddPostOptionsLine(string.Empty);
47+
help.AddPostOptionsLine("Example:");
48+
help.AddPostOptionsLine(" > colorCat add -c red -i error");
49+
help.AddPostOptionsLine(string.Empty);
50+
break;
51+
}
3052

31-
var help = new HelpText
53+
if (string.IsNullOrEmpty(verb))
3254
{
33-
Heading = new HeadingInfo(asm.GetName().Name, asm.GetName().Version.ToString()),
34-
AdditionalNewLineAfterOption = true,
35-
AddDashesToOption = true
36-
};
55+
help.AddDashesToOption = false;
56+
}
57+
else
58+
{
59+
help.AddDashesToOption = true;
60+
help.AddPreOptionsLine(verb);
61+
}
3762

38-
AddCopyright(help);
39-
help.AddOptions(this);
4063
return help;
4164
}
4265

@@ -50,5 +73,23 @@ private static void AddCopyright(HelpText help)
5073
help.AddPreOptionsLine(copyright);
5174
}
5275
}
76+
77+
public class AddOption
78+
{
79+
[Option('c', "color", Required = true, HelpText = "The color to use for the mapping.")]
80+
public ConsoleColor Color { get; set; }
81+
82+
[Option('i', "ignoreCase", HelpText = "Ignore case when executing the mapping.")]
83+
public bool IgnoreCase { get; set; }
84+
85+
[Option('r', "regex", HelpText = "Execute mapping as a regular expression instead of a string compare.")]
86+
public bool IsRegex { get; set; }
87+
88+
[ValueList(typeof(List<string>))]
89+
public IList<string> Pattern { get; set; }
90+
91+
[Option('v', "verbose", HelpText = "Display configuration after the update")]
92+
public bool Verbose { get; set; }
93+
}
5394
}
5495
}

ColorCat/Program.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@ public class Program
77
{
88
public static void Main(string[] args)
99
{
10-
var options = new ColorCatOptions();
11-
12-
if (CommandLine.Parser.Default.ParseArguments(args, options))
10+
if (args == null || args.Length == 0)
1311
{
14-
if (options.Add)
15-
{
16-
AddConfig(options);
17-
}
18-
else
12+
Run();
13+
}
14+
else
15+
{
16+
var options = new ColorCatOptions();
17+
18+
if (CommandLine.Parser.Default.ParseArguments(args, options, (_, __) => { }))
1919
{
20-
Run(options);
20+
if (options.Add != null)
21+
{
22+
AddConfig(options.Add);
23+
}
2124
}
2225
}
2326
}
2427

25-
public static void Run(ColorCatOptions options)
28+
public static void Run()
2629
{
2730
var config = Configuration.Load();
2831

@@ -55,19 +58,22 @@ public static void Run(ColorCatOptions options)
5558
}
5659
}
5760

58-
private static void AddConfig(ColorCatOptions options)
61+
private static void AddConfig(ColorCatOptions.AddOption options)
5962
{
6063
var config = Configuration.Load();
6164
var newMapping = CreateMapping(options);
6265
config.Mappings.Add(newMapping);
6366

6467
var mappingJson = config.Save();
6568

66-
Console.WriteLine("Added mapping. Current mappings are:");
67-
Console.WriteLine(mappingJson);
69+
if (options.Verbose)
70+
{
71+
Console.WriteLine("Added mapping. Current mappings are:");
72+
Console.WriteLine(mappingJson);
73+
}
6874
}
6975

70-
private static ColorMapping CreateMapping(ColorCatOptions options)
76+
private static ColorMapping CreateMapping(ColorCatOptions.AddOption options)
7177
{
7278
var mapping = new ColorMapping
7379
{

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,52 @@ This tool will read from standard input and output colored text to the console.
66

77
![](ScreenShot.png)
88

9+
10+
## Usage
11+
12+
### Basic Usage
13+
14+
To colorize the output of another program (such as tail or cat) simply pipe into colorCat.
15+
16+
> tail -f myLogFile | colorCat
17+
> cat data | colorCat
18+
19+
The first time you do this, if colorCat has not been configured, a default configuration will be created.
20+
21+
### add
22+
Adds a new color mapping filter to your configuration.
23+
24+
```
25+
-c, --color Required. The color to use for the mapping.
26+
27+
-i, --ignoreCase Ignore case when executing the mapping.
28+
29+
-r, --regex Execute mapping as a regular expression instead of a
30+
string compare.
31+
32+
-v, --verbose Display configuration after the update
33+
34+
Valid colorss are:
35+
Black
36+
DarkBlue
37+
DarkGreen
38+
DarkCyan
39+
DarkRed
40+
DarkMagenta
41+
DarkYellow
42+
Gray
43+
DarkGray
44+
Blue
45+
Green
46+
Cyan
47+
Red
48+
Magenta
49+
Yellow
50+
White
51+
52+
Example:
53+
colorCat add -c red -i error
54+
```
55+
956
## Downloads
10-
[ColorCat](https://github.com/MasterDevs/ColorCat/releases/download/V0.0.2/bin.zip)
57+
[ColorCat](https://github.com/MasterDevs/ColorCat/releases/download/V0.0.4/bin.zip)

0 commit comments

Comments
 (0)