github-actions[bot] on v4.5.0
jeremydmiller on master
option to also clear state on a… (compare)
github-actions[bot] on v4.4.0
jeremydmiller on master
new extension methods for rebui… (compare)
github-actions[bot] on v4.3.1
jeremydmiller on master
changing the resources display … (compare)
github-actions[bot] on v4.3.0
jeremydmiller on master
Workaround for extension servic… (compare)
github-actions[bot] on v4.2.0
dependabot[bot] on npm_and_yarn
Bump prismjs from 1.25.0 to 1.2… (compare)
jeremydmiller on master
ran the stdocs to vitepress con… *mostly* converted docs to Vite… deleting obsolete stdocs docume… and 9 more (compare)
@hmvs the closest I can get to what you are after is this:
public class MigrateCommand : OaktonCommand<MigrateInput>
{
public MigrateCommand()
{
Usage("Migrate things")
.Arguments(x => x.ConnectionString)
.ValidFlags(x => x.PathsFlag, x => x.AlwaysRunFlag);
}
public override bool Execute(MigrateInput input)
{
if (input.PathsFlag == null || input.PathsFlag.Any() == false)
{
ConsoleWriter.Write(ConsoleColor.Red, "You must specify the Paths flag");
return false;
}
if (input.AlwaysRunFlag == null || input.AlwaysRunFlag.Any() == false)
{
ConsoleWriter.Write(ConsoleColor.Red, "You must specify the AlwaysRun flag");
return false;
}
Console.WriteLine($"ConnectionString: {input.ConnectionString}");
Console.WriteLine("Paths:");
foreach (var path in (input.PathsFlag ?? Enumerable.Empty<string>()))
Console.WriteLine($" - {path}");
Console.WriteLine("Always:");
foreach (var path in (input.AlwaysRunFlag ?? Enumerable.Empty<string>()))
Console.WriteLine($" - {path}");
return true;
}
}
public class MigrateInput
{
public string ConnectionString { get; set; }
public IEnumerable<string> PathsFlag { get; set; }
public IEnumerable<string> AlwaysRunFlag { get; set; }
}
usage:
dotnet run -- localhost --paths /d/dev/tmp/1.sql /d/dev/tmp/2.sql --always-run /d/dev/tmp/3.sql
You can achive something like what you are after...but it's not entirely pleasant. It involves using an argument and a flag, and specifying usages so that you either can use "argument + flag" or "flag + flag":
public class TestInput
{
public string One { get; set; }
public string OneFlag { get; set; }
public string TwoFlag { get; set; }
}
public class TestCommand : OaktonCommand<TestInput>
{
public TestCommand()
{
Usage("default flag").Arguments(x => x.One).ValidFlags(x => x.TwoFlag);
Usage("do it yourself flag").ValidFlags(x => x.OneFlag, x => x.TwoFlag);
}
public override bool Execute(TestInput input)
{
Console.WriteLine($"1: {input.One ?? input.OneFlag}");
Console.WriteLine($"2: {input.TwoFlag}");
return true;
}
}
Example usage:
# working usages:
dotnet OaktonTesting.dll test --one wat --two is
dotnet OaktonTesting.dll test wat --two is
# throws an error, as this is not a valid usage:
dotnet OaktonTesting.dll test omg --one wat --two is
Hello i have an opts file where i defined some flags, when running my command the program appends the flags this way
mytool -u MyUserName -p ~~HeMan2345 somecommand
instead of
mytool somecommand -u MyUserName -p ~~HeMan2345
which gives me an error : -u is not a command
Any tips ?! Thanks
Hey guys. great library! thank you!
Log.Information("Starting web host");
return CreateHostBuilder(args).RunOaktonCommands(args);
//CreateHostBuilder(args).Build().Run();
//return Task.FromResult(0);
anyone know why I lose my logs when i use the oakton commands instead? all I get is the one log before serilog is supposed to take over
webroot
and the listen port
from from commandline args using Oakton. Oakton command line args should override what may have already been set by appsettings.json
or appsettings.Development.json
. Can this be done somehow?public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(
webBuilder =>
{
// There are two problems with the following two lines.
// 1. Where do I get configuration instance from?
// 2. How do I merge them with Okaton commandline args?
webBuilder.UseWebRoot(configuration.GetValue<string>("MySection:webroot"));
webBuilder.UseUrls($"http://localhost:{configuration.GetValue<int>("MySection:port")}");
webBuilder.UseStartup<Startup>();
});
}
public class Startup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
}
}
[2021-05-03 16:05:42Z] [FTL] [<s:>] WebApp failed to start.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.CodeAnalysis, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
at System.Reflection.CustomAttribute.IsDefined(RuntimeAssembly assembly, RuntimeType caType)
at System.Reflection.RuntimeAssembly.IsDefined(Type attributeType, Boolean inherit)
at System.Attribute.IsDefined(Assembly element, Type attributeType, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.IsDefined(Assembly element, Type attributeType)
at Baseline.Reflection.ReflectionExtensions.HasAttribute[T](Assembly provider)
at Oakton.CommandFactory.<>c.<RegisterCommandsFromExtensionAssemblies>b__30_0(Assembly a)
dotnet run ...
doesn't even work without the project file.
dotnet run [assembly file name]
. It’s been awhile since I’ve done that, so it might be a flag of some sort
In dotnet core, dotnet run app.exe
or any file produces a response like the following:
Couldn't find a project to run. Ensure a project exists in C:\code\publish\App, or pass the path to the project using --project.
From the dotnet-run docs:
The dotnet run command is used in the context of projects, not built assemblies. If you're trying to run a framework-dependent application DLL instead, you must use dotnet without a command.
Are people only using Oakton on source projects or on release builds as well?
FileNotFoundException
, it’s unable to load the assembly referenced. You might try making a direct dependency to that nuget package w/ that version