Problem with CommandLineParser
Opened this issue · 14 comments
Hello everyone, nice idea!
I am trying to parse but my dll is external and it will pass method with CommandLine's reference from external dll and It doesn't see like GameWindow of OpenTK I will try width and height.
example:
myapp.exe is default size 1024 768.
myapp.exe -width 1200 -height 768
Example my code:
using CommandLine;
using OpenTK;
namespace Engine
{
public class Client
{
private SDLWindow game;
public void Host(string[] args)
{
game = new SDLWindow();
var hlCommandOpts = new HLCommandOptions();
if(Parser.Default.ParseArguments(args, hlCommandOpts))
{
// -width
if (hlCommandOpts.Width != 0)
game.Width = hlCommandOpts.Width;
// -height
if (hlCommandOpts.Height != 0)
game.Height = hlCommandOpts.Height;
}
else
{
game.Width = 1024;
game.Height = 768;
}
game.Run(60);
}
private sealed class SDLWindow : GameWindow
{
public SDLWindow()
{
WindowBorder = WindowBorder.Fixed;
//Location = new Point((SystemInformation.PrimaryMonitorSize.Width / 2) - (Width / 2), (SystemInformation.PrimaryMonitorSize.Height / 2) - (Height / 2));
}
}
private class HLCommandOptions
{
[Option("-width", Required = true)]
public int Width
{
get; set;
}
[Option("-height", Required = true)]
public int Height
{
get; set;
}
[Option("-game", Required = true)]
public string GameDir
{
get; set;
}
}
}
}
is Engine.dll and
my myapp
using System;
using System.Reflection;
namespace myapp
{
class Program
{
static void Main(string[] args)
{
var DLL = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "Engine.dll");
var class1Type = DLL.GetType("Engine.Client");
var c = Activator.CreateInstance(class1Type);
var method = class1Type.GetMethod("Host");
method.Invoke(c, new object[] { args });
}
}
}
Run GameWindow normal with current width 1024 and current height 768.
It doesn't see for changing width and height? If I change width and height via powershell example
./myapp.exe -width 800 -height 640
than game window doesn't change - If I use this
game.width = options.width;
game.height = options.height;
Is it wrong or it doesn't support for external dll?
Are you able to get the argument values passed in your HLCommandOptions object? Can you run your program in debug mode and confirm that?
Yes i already usd debug mode. But passing arguments don't see to work? I will show you later if i capture video.
Sure, do you mean to say that hlCommandOpts after Parser.Default.ParseArguments(args, hlCommandOpts) statement does not have any value?
"Sure, do you mean to say that hlCommandOpts after Parser.Default.ParseArguments(args, hlCommandOpts) statement does not have any value?"
It is correct!!!
I don't know why does it happen?
Check video!
https://www.youtube.com/watch?v=tfPGBLRcBJQ
Two problems I see:
- Don't include the
-in your option definition, it is added automatically. - Option names with more than one character (e.g. 'width') require a double dash (
--width), not a single dash like in Powershell.
Try these and see if it fixes your issue.
I have same problem :( I use other PowerArgs library because it has only single dash.
Sorry I already tried --width and --height than it doesn't work for me :( So sad... And without dashes "width" and "height" not working too :( I can not understand now. I explain you - I think CommandLine Parser doesn't work for external dll. Did you try external dll if commandline parser works fine with external dll???
Thanks for trying resolves,...
If you're using [Option("height", Required = true)] and --height at the command line and it's still not working, please try the Prerelease nuget package and see if that fixes things. There is no problem with external DLLs.
Hello @nemec I did it. But it can not work for --width and --height. nothing. Why does it always not work? I already upgraded to pre version but nothing..... I can not understand yet.
I wish i give you my solution - I think i am not sure because you're real helper of owner @yrshaikh by CommandLineParser? Or I didn't see if it is correct developer of CommandLineParser?
( Removed Download )
I hope you have result if it has problem than you can give me resolve. Thanks!
Don't forget if you click "Rebuild" or "Build" than hlSharp -> ContentMenu -> Add existing file -> Engine.dll from Engine/bin/Debug/Engine.dll and Make sure "Don't copy" to "Copy always" than Build and Run with hlSharp and Go to hlSharp/bin/Debug and open Command or Powershell than
Type for Command:
hlSharp.exe --width 1280 --height 1024
or type for PowerShell
./hlSharp.exe --width 1280 --height 1024
Did you see if GameWindow changes width and height from command or powershell than it changed with current width and current height by typing command line....
Thanks!
FYI your 'game' parameter is marked as required, so if you are not providing it on the command line that could be another problem.
I don't understand what do you mean? "game" parameter is marked as requiered? What is other problem. Did you find my zip ( I am using Visual Studio 2017 Community. )
vvvv
[Option("game", Required = true)]
public string GameDir
{
get; set;
}
Just remove that or set it false. Sorry I can't run your download at work.
Impossible you say your download process doesn't work?
Did you use Chrome? Maybe Github has problem? I think you didn't try again. ( Removed Download )
Do you mean CommandLineParse doesn't work with single dash. Do you think ManyConsole ( renamed from NDesk.Console ) or PowerArgs have single dash. But I don't understand why does game with parameters not work if it is just real parameters of Half-Life's launch options - I want surprise to Valve Software that is why I want be good C# writer like you too. That is why I wish real parameters like Half-Life's parameters example Scroll down and find "hl.exe"
Syntax: hl.exe #parameter1 #parameter2 #cvar1 #cvar2
Example hl.exe -width 1024 -height 660
But I don't like -- or // just "-" and "+" that is why.
Thanks for understanding!
Or my download still not working?
They are liars because yoh don't answer me? Thanks i will punish you now. I have found Plossum is like CommandlineParser alternatives. I close now and I am getting angry now i remove downloads. I am mad because they don't support my resolve. Thanks bye!