Skip to content

Commit

Permalink
Add --version command line option
Browse files Browse the repository at this point in the history
  - Add `--version` option with copyright and license info with tests
  - Add repository URL to GLedApiDotNet metadata
  - Adjust name to "RGB Fusion Tool" in metadata
  • Loading branch information
tylerszabo committed Jun 6, 2018
1 parent 6ba79d0 commit 6cb2039
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GLedApiDotNet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("GLedApiDotNet")]
[assembly: AssemblyDescription(".NET wrapper for Gigabyte's RGB Fusion GLedApi.dll")]
[assembly: AssemblyDescription(".NET wrapper for Gigabyte's RGB Fusion GLedApi.dll - Source: https://github.com/tylerszabo/RGB-Fusion-Tool")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GLedApiDotNet")]
Expand Down
33 changes: 33 additions & 0 deletions RGBFusionTool/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private class ApplicationContext
{
public bool flag_Help;
public bool flag_List;
public bool flag_Version;
public int verbosity;

public ApplicationContext()
Expand All @@ -37,6 +38,7 @@ public void SetDefaults()
{
flag_Help = false;
flag_List = false;
flag_Version = false;
verbosity = 0;
}
}
Expand Down Expand Up @@ -72,6 +74,7 @@ public Application(IRGBFusionMotherboard motherboardLEDs, TextWriter stdout, Tex
{ "v|verbose", v => context.verbosity++ },
{ "l|list", "list zones", v => context.flag_List = true },
{ "?|h|help", "show help and exit", v => context.flag_Help = true },
{ "version", "show version information and exit", v => context.flag_Version = true },
{ "" }
};

Expand Down Expand Up @@ -129,6 +132,30 @@ private void ShowHelp(TextWriter o)
}
}

private void ShowVersion(TextWriter o)
{
string gplNotice =
@"This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.";

o.WriteLine("RGB Fusion Tool {0}", System.Reflection.Assembly.GetAssembly(this.GetType()).GetName().Version);
o.WriteLine("Copyright (C) 2018 Tyler Szabo");
o.WriteLine();
o.WriteLine(gplNotice);
o.WriteLine();
o.WriteLine("Source: https://github.com/tylerszabo/RGB-Fusion-Tool");
}

public void Main(string[] args)
{
context.SetDefaults();
Expand All @@ -143,6 +170,12 @@ public void Main(string[] args)
return;
}

if (context.flag_Version)
{
ShowVersion(stdout);
return;
}

zoneOptions.Parse(afterGeneric);

if (context.flag_List || context.verbosity > 0)
Expand Down
4 changes: 2 additions & 2 deletions RGBFusionTool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RGBFusionTool")]
[assembly: AssemblyTitle("RGB Fusion Tool")]
[assembly: AssemblyDescription("Tool for Gigabyte's RGB Fusion motherboard LEDs")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RGBFusionTool")]
[assembly: AssemblyProduct("RGB Fusion Tool")]
[assembly: AssemblyCopyright("Copyright © 2018 Tyler Szabo")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand Down
29 changes: 28 additions & 1 deletion RGBFusionToolTests/RGBFusionToolExeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void Help(string[] args)

"verbose",
"list",
"help"
"help",
"version"
};
foreach (string option in supportedOptions)
{
Expand All @@ -86,6 +87,32 @@ public void Help(string[] args)
}
}

[DataRow(new string[] { "--version" }, DisplayName = "--version")]
[DataTestMethod]
public void Version(string[] args)
{
rgbFusionTool.Main(args);

Assert.IsFalse(mock.IsInitialized, "Expect uninitialized");
StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty");

string[] requiredPatterns = {
"\\bRGB Fusion Tool\\b\\s+\\b\\d+(\\.\\d+){1,3}\\b", // name and version
"\\b[cC]opyright\\b\\s+(\\([cC]\\)\\s+)\\b2018\\b\\s+\\bTyler Szabo\\b", // copyright year and name

"\\bGNU General Public License\\b",
"\\bFree Software Foundation\\b",
"\\bversion 3\\b",
"\\bWITHOUT ANY WARRANTY\\b",
"https://www.gnu.org/licenses/"
};
foreach (string pattern in requiredPatterns)
{
Regex regex = new Regex(pattern);
StringAssert.Matches(stdout.ToString(), regex, "Expect stdout shows version information");
}
}

[TestMethod]
public void NoArgs()
{
Expand Down

0 comments on commit 6cb2039

Please sign in to comment.