-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c93af54
commit e80e27d
Showing
7 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace TcHaxx.Snappy.CLI; | ||
|
||
internal static class Constants | ||
{ | ||
/// <summary> | ||
/// Default delimiter for CLI info. | ||
/// </summary> | ||
internal const char CLI_DELIMITER = '*'; | ||
|
||
internal const string DEFAULT_COPYRIGHT = "Copyright (c) 2024 densogiaichned"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace TcHaxx.Snappy.CLI; | ||
|
||
/// <summary> | ||
/// Some helper methods/functions and extension methods. | ||
/// </summary> | ||
internal static class Helper | ||
{ | ||
/// <summary> | ||
/// Centers a <see cref="string"/>. | ||
/// </summary> | ||
/// <param name="this"></param> | ||
/// <returns>centered string</returns> | ||
internal static string Center(this string @this) | ||
{ | ||
|
||
if (string.IsNullOrEmpty(@this)) | ||
{ | ||
return string.Empty; | ||
} | ||
var width = Console.BufferWidth; | ||
return @this.PadLeft(((width - @this.Length) / 2) | ||
+ @this.Length) | ||
.PadRight(width); | ||
} | ||
|
||
/// <summary> | ||
/// Prints the application header based on <see cref="Assembly"/>-attributes as <see cref="string"/>. | ||
/// </summary> | ||
/// <param name="assembly"></param> | ||
/// <returns></returns> | ||
internal static string GetApplicationHeader(Assembly assembly) | ||
{ | ||
var sb = new StringBuilder(1000); | ||
|
||
var version = assembly.GetName().Version; | ||
var copyright = assembly.GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright ?? Constants.DEFAULT_COPYRIGHT; | ||
|
||
var repoUrl = assembly.GetCustomAttributes<AssemblyMetadataAttribute>() | ||
.Where(x => x.Key.Equals("RepositoryUrl")) | ||
.FirstOrDefault()?.Value ?? string.Empty; | ||
|
||
var delimiter = new string(Constants.CLI_DELIMITER, Console.BufferWidth); | ||
sb.Append($"{delimiter}\n"); | ||
sb.Append($"{assembly.GetName().Name} V{version}".Center() + "\n"); | ||
sb.Append($"{copyright.Center()}\n"); | ||
if (!string.IsNullOrWhiteSpace(repoUrl)) | ||
{ | ||
sb.Append($"{repoUrl.Center()}\n"); | ||
} | ||
|
||
sb.Append($"{delimiter}\n"); | ||
|
||
return sb.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters