-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: SonarQube | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
jobs: | ||
build: | ||
name: Build and analyze | ||
runs-on: windows-latest | ||
steps: | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 17 | ||
distribution: 'zulu' # Alternative distribution options are available. | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
- name: Cache SonarQube Cloud packages | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~\sonar\cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
- name: Cache SonarQube Cloud scanner | ||
id: cache-sonar-scanner | ||
uses: actions/cache@v4 | ||
with: | ||
path: .\.sonar\scanner | ||
key: ${{ runner.os }}-sonar-scanner | ||
restore-keys: ${{ runner.os }}-sonar-scanner | ||
- name: Install SonarQube Cloud scanner | ||
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' | ||
shell: powershell | ||
run: | | ||
New-Item -Path .\.sonar\scanner -ItemType Directory | ||
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner | ||
- name: Build and analyze | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
shell: powershell | ||
run: | | ||
.\.sonar\scanner\dotnet-sonarscanner begin /k:"devexlead_devex-cli" /o:"devexlead" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" | ||
dotnet build | ||
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
using System.CommandLine; | ||
using System.CommandLine.Builder; | ||
using System.CommandLine.Parsing; | ||
using DevEx.Core; | ||
|
||
var rootCommand = new RootCommand(); | ||
return await rootCommand.InvokeAsync(args); | ||
|
||
PluginService.LoadPlugins(rootCommand); | ||
|
||
var builder = new CommandLineBuilder(rootCommand) | ||
.UseDefaults() | ||
.UseSuggestDirective(); | ||
|
||
var parser = builder.Build(); | ||
return await parser.InvokeAsync(args); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"profiles": { | ||
"dx": { | ||
"DevEx.Console": { | ||
"commandName": "Project", | ||
"commandLineArgs": "dx --version" | ||
"commandLineArgs": "--version" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.CommandLine; | ||
|
||
namespace DevEx.Core | ||
{ | ||
public interface IPlugin | ||
{ | ||
string Name { get; } | ||
string Description { get; } | ||
Command GetCommand(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.CommandLine; | ||
|
||
namespace DevEx.Core | ||
{ | ||
public class PluginService | ||
{ | ||
public static void LoadPlugins(RootCommand rootCommand) | ||
{ | ||
var pluginAssemblies = Directory.GetFiles(AppContext.BaseDirectory, "DevEx.Plugins.*.dll"); | ||
foreach (var assemblyPath in pluginAssemblies) | ||
{ | ||
try | ||
{ | ||
var assembly = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath); | ||
|
||
var pluginTypes = assembly.GetTypes() | ||
.Where(type => typeof(IPlugin) | ||
.IsAssignableFrom(type) && !type.IsInterface); | ||
|
||
foreach (var type in pluginTypes) | ||
{ | ||
if (Activator.CreateInstance(type) is IPlugin plugin) | ||
{ | ||
#if DEBUG | ||
Console.WriteLine($"Loading plugin: {plugin.Name} - {plugin.Description}"); | ||
#endif | ||
var command = plugin.GetCommand(); | ||
rootCommand.AddCommand(command); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Failed to load plugins from {assemblyPath}: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.CommandLine; | ||
using DevEx.Core; | ||
|
||
namespace DevEx.Plugins.Vault | ||
{ | ||
public class SamplePlugin : IPlugin | ||
{ | ||
public string Name => "vault"; | ||
public string Description => "Manage items in the vault"; | ||
|
||
public Command GetCommand() | ||
{ | ||
var vaultCommand = new Command(Name, Description); | ||
|
||
// Create subcommands for actions | ||
Command createCommand = BuildCreateCommand(); | ||
Command deleteCommand = BuildDeleteCommand(); | ||
Command modifyCommand = BuildModifyCommand(); | ||
Command readCommand = BuildReadCommand(); | ||
|
||
// Add subcommands to the main vault command | ||
vaultCommand.AddCommand(createCommand); | ||
vaultCommand.AddCommand(deleteCommand); | ||
vaultCommand.AddCommand(modifyCommand); | ||
vaultCommand.AddCommand(readCommand); | ||
|
||
return vaultCommand; | ||
} | ||
|
||
private static Command BuildReadCommand() | ||
{ | ||
var readCommand = new Command("read", "Fetch an item from the vault") | ||
{ | ||
new Option<string>("--key", "The key of the item to fetch") | ||
}; | ||
readCommand.SetHandler((string key) => | ||
{ | ||
if (string.IsNullOrWhiteSpace(key)) | ||
{ | ||
Console.WriteLine("--key is required for read."); | ||
return; | ||
} | ||
Console.WriteLine($"Fetched item with Key={key}"); | ||
}, | ||
readCommand.Options[0] as Option<string>); | ||
Check warning on line 45 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs
|
||
return readCommand; | ||
} | ||
|
||
private static Command BuildModifyCommand() | ||
{ | ||
var modifyCommand = new Command("modify", "Modify an item in the vault") | ||
{ | ||
new Option<string>("--key", "The key of the item to modify"), | ||
new Option<string>("--value", "The new value of the item") | ||
}; | ||
modifyCommand.SetHandler((string key, string value) => | ||
{ | ||
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value)) | ||
{ | ||
Console.WriteLine("Both --key and --value are required for modify."); | ||
return; | ||
} | ||
Console.WriteLine($"Modified item: Key={key}, New Value={value}"); | ||
}, | ||
modifyCommand.Options[0] as Option<string>, | ||
Check warning on line 65 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs
|
||
modifyCommand.Options[1] as Option<string>); | ||
Check warning on line 66 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs
|
||
return modifyCommand; | ||
} | ||
|
||
private static Command BuildDeleteCommand() | ||
{ | ||
var deleteCommand = new Command("delete", "Remove an item from the vault") | ||
{ | ||
new Option<string>("--key", "The key of the item to remove") | ||
}; | ||
deleteCommand.SetHandler((string key) => | ||
{ | ||
if (string.IsNullOrWhiteSpace(key)) | ||
{ | ||
Console.WriteLine("--key is required for delete."); | ||
return; | ||
} | ||
Console.WriteLine($"Deleted item with Key={key}"); | ||
}, | ||
deleteCommand.Options[0] as Option<string>); | ||
Check warning on line 85 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs
|
||
return deleteCommand; | ||
} | ||
|
||
private static Command BuildCreateCommand() | ||
{ | ||
var createCommand = new Command("create", "Add an item to the vault") | ||
{ | ||
new Option<string>("--key", "The key of the item to add"), | ||
new Option<string>("--value", "The value of the item to add") | ||
}; | ||
createCommand.SetHandler((string key, string value) => | ||
{ | ||
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value)) | ||
{ | ||
Console.WriteLine("Both --key and --value are required for create."); | ||
return; | ||
} | ||
Console.WriteLine($"Created item: Key={key}, Value={value}"); | ||
}, | ||
createCommand.Options[0] as Option<string>, | ||
Check warning on line 105 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs
|
||
createCommand.Options[1] as Option<string>); | ||
Check warning on line 106 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs
|
||
return createCommand; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\DevEx.Core\DevEx.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |