-
-
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.
Merge pull request #18 from Crequency/dev=main
[Pull Request] New powerful cli tool project
- Loading branch information
Showing
10 changed files
with
232 additions
and
32 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,42 @@ | ||
name: Publish | ||
|
||
on: | ||
push: | ||
branches: ["main", "dev=main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
build-on-ubuntu: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: | | ||
8.0.x | ||
- name: Add to GitHub Repo | ||
if: ${{ github.event_name != 'pull_request' }} | ||
run: | | ||
nuget sources add -name github -Source https://nuget.pkg.github.com/Crequency/index.json -Username Crequency -Password ${{ secrets.GitHubToken }} | ||
- name: Install NuGet | ||
uses: nuget/setup-nuget@v1 | ||
if: ${{ github.event_name != 'pull_request' }} | ||
with: | ||
nuget-version: "6.x" | ||
|
||
- name: Build and Publish Cli Tool | ||
working-directory: "Common.BasicHelper.Cli" | ||
if: ${{ github.event_name != 'pull_request' }} | ||
run: | | ||
dotnet build -c Release | ||
nuget push ./bin/Release/*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} -NoSymbol | ||
nuget push ./bin/Release/*.nupkg -Source github -SkipDuplicate |
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,13 @@ | ||
using CommandLine; | ||
|
||
namespace Common.BasicHelper.Cli.Arguments; | ||
|
||
public class BasicOptions | ||
{ | ||
|
||
[Option("verbose", HelpText = "Display verbose output.")] | ||
public bool Verbose { get; set; } | ||
|
||
[Option("dry-run", HelpText = "Dry run the command.")] | ||
public bool DryRun { get; set; } | ||
} |
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,81 @@ | ||
using CommandLine; | ||
using Common.BasicHelper.Utils; | ||
|
||
namespace Common.BasicHelper.Cli.Arguments.Verbs; | ||
|
||
[Verb("password", aliases: ["passwd", "pwd"], HelpText = "Password related utils.")] | ||
public class VerbPassword : BasicOptions | ||
{ | ||
[Option('g', "generate", Default = true, HelpText = "Generate a password.")] | ||
public bool Generate { get; set; } | ||
|
||
[Option('l', "length", Default = 12, HelpText = "Length of the password.")] | ||
public int Length { get; set; } | ||
|
||
[Option('r', "length-range", HelpText = "Length range of the password, like `3,5`.")] | ||
public string? LengthRange { get; set; } | ||
|
||
[Option('u', "ignore-uppercase", HelpText = "Ignore uppercase letters.")] | ||
public bool IgnoreUppercase { get; set; } | ||
|
||
[Option('e', "ignore-lowercase", HelpText = "Ignore lowercase letters.")] | ||
public bool IgnoreLowercase { get; set; } | ||
|
||
[Option('n', "ignore-numbers", HelpText = "Ignore numbers.")] | ||
public bool IgnoreNumbers { get; set; } | ||
|
||
[Option('s', "ignore-symbols", HelpText = "Ignore symbols.")] | ||
public bool IgnoreSymbols { get; set; } | ||
|
||
[Option('U', "supported-uppercase", Default = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", HelpText = "Supported uppercase letters.")] | ||
public string? SupportedUppercase { get; set; } | ||
|
||
[Option('E', "supported-lowercase", Default = "abcdefghijklmnopqrstuvwxyz", HelpText = "Supported lowercase letters.")] | ||
public string? SupportedLowercase { get; set; } | ||
|
||
[Option('N', "supported-numbers", Default = "0123456789", HelpText = "Supported numbers.")] | ||
public string? SupportedNumbers { get; set; } | ||
|
||
[Option('S', "supported-symbols", Default = "!@#$%^&*()_+-=[]{};':,./<>?", HelpText = "Supported symbols.")] | ||
public string? SupportedSymbols { get; set; } | ||
} | ||
|
||
public static class PasswordExtensions | ||
{ | ||
public static VerbPassword Execute(this VerbPassword pwdc) | ||
{ | ||
int lengthRangeStart = 0; | ||
int lengthRangeEnd = 0; | ||
|
||
var lengthRangeProvided = pwdc.LengthRange is not null; | ||
|
||
if (pwdc.LengthRange is not null) | ||
{ | ||
var splited = pwdc.LengthRange.Split(','); | ||
|
||
if (splited.Length != 2) | ||
throw new ArgumentException("Length range should be like `3,5`."); | ||
|
||
lengthRangeProvided = lengthRangeProvided && int.TryParse(splited[0], out lengthRangeStart); | ||
lengthRangeProvided = lengthRangeProvided && int.TryParse(splited[1], out lengthRangeEnd); | ||
} | ||
|
||
var pwd = Password.GeneratePassword( | ||
pwdc.Length, | ||
lengthRangeProvided ? lengthRangeStart : null, | ||
lengthRangeProvided ? lengthRangeEnd : null, | ||
pwdc.IgnoreUppercase == false, | ||
pwdc.IgnoreLowercase == false, | ||
pwdc.IgnoreNumbers == false, | ||
pwdc.IgnoreSymbols == false, | ||
pwdc.SupportedUppercase!, | ||
pwdc.SupportedLowercase!, | ||
pwdc.SupportedNumbers!, | ||
pwdc.SupportedSymbols! | ||
); | ||
|
||
Console.WriteLine(pwd); | ||
|
||
return pwdc; | ||
} | ||
} |
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,52 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<AssemblyVersion>$(Version)</AssemblyVersion> | ||
<FileVersion>$(Version)</FileVersion> | ||
<Version>0.1.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-06-06"))).TotalDays).$([System.Math]::Floor($([System.DateTime]::UtcNow.TimeOfDay.TotalMinutes)))</Version> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Authors>Dynesshely</Authors> | ||
<Company>Crequency</Company> | ||
<Copyright>Copyright (C) Crequency 2024</Copyright> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> | ||
<RepositoryUrl>https://github.com/Crequency/Common.BasicHelper/</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/Crequency/Common.BasicHelper/</PackageProjectUrl> | ||
<PackageLicenseExpression>AGPL-3.0-only</PackageLicenseExpression> | ||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance> | ||
<PackageId>$(AssemblyName)</PackageId> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PackAsTool>true</PackAsTool> | ||
<ToolCommandName>cbt</ToolCommandName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="icon.png" Pack="True" PackagePath="\" /> | ||
<None Include="..\README.md" Pack="True" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Common.BasicHelper.Samples\Common.BasicHelper.Samples.csproj" /> | ||
<ProjectReference Include="..\Common.BasicHelper\Common.BasicHelper.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.9.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,6 @@ | ||
using CommandLine; | ||
using Common.BasicHelper.Cli.Arguments.Verbs; | ||
|
||
Parser.Default.ParseArguments<VerbPassword, object>(args) | ||
.WithParsed<VerbPassword>(options => options.Execute()) | ||
; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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