コンソール引数の解析とスクリプトの自動化を自動化するライブラリ。
コマンドラインの解析は、通常この方法でアプローチされるものです。引数の構文を定義し、コマンドラインパーサーライブラリを使用して解析し、パラメーターをApplciationに使用します。このアプローチには多くのステップが必要であり、マンテンは困難です。このライブラリは、すべてのステップですべてのステップを1つだけ崩壊させます。メソッドを説明してください。
どこかにメソッドを宣言し、その上に注釈を追加して、物事を自動にする必要があります。もう1つの興味深いシナリオは、config yamlファイルによる複数のコマンドの実行です(Dockerファイルメカニズムと同様)。
Exampeを参照して、これによりコンソールアプリケーションがどのように簡素化されるかを学びます。
Install-Package ConsoleAuto
class Program
{
static void Main ( string [ ] args )
{
ConsoleAuto . Config ( args )
. LoadCommands ( )
. Run ( ) ;
}
[ ConsoleCommand ]
public void MyMethod ( string inputOne , int inputTwo )
{
//do stuff here
}
}このプログラムは実行可能になります:
Myprogram MyMethod --inputOne xxxx --inputTwo 23
ConsoleCommandによって注釈が付けられた各方法は、呼び出されるために利用できます。メソッドは、プログラムファイルのクラスで静的かどうかにかかわらずにできます。非静的クラスはDIを使用して作成され、コステラチャーの依存関係を受信できます。デフォルトのコマンドは、使用情報を表示する情報(コマンド定義から自動的に生成されます)です。
public class IOCommands
{
public ConsoleService consoleService ;
public IOCommands ( ConsoleService consoleService )
{
this . consoleService = consoleService ;
}
[ ConsoleCommand ( isPublic : false , info : "provide this description" ) ]
public void WriteText ( string text , bool newline )
{
//do stuff here
}
} ConsoleAuto . Config ( args , servicecollection ) // pass servicecollection to use the same container of main application
. LoadCommands ( ) //Load all commands from entry assembly + base commands
. LoadCommands ( assembly ) //Load from a custom command
. LoadFromType ( typeof ( MyCommand ) ) //load a single command
. Register < MyService > ( ) // add a service di di container used in my commands
. Register < IMyService2 > ( new Service2 ( ) ) // add a service di di container used in my commands, with a custom implementation
. Default ( "MyDefaultCommand" ) //specify the default action if app starts without any command
. Configure ( config => {
//hack the config here
} )
. Run ( ) ; | 方法 | 注記 |
|---|---|
| config | INFサービスコレクションはnullで、diの内部コンテナを作成します |
| LoadCommand | エントリアセンブリ +ベースコマンドからすべてのコマンドをロードし、注釈に基づいています |
| 登録する | コマンドの依存関係を登録します。メインアプリケーションでDIを使用している場合、メインDIコンテナにも依存関係が追加されます。 DIを使用していて、すでに依存関係を追加している場合は、登録する必要はありません。 |
| 設定します | これにより、結果の構成が公開されます。あなたのリスクで使用してください。 |
| 走る | プログラムを実行します |
| デフォルト | コマンドが指定されていない場合にコマンドが実行されました。デフォルト値は情報コマンドです。 |
| パラメーター | 注記 |
|---|---|
| 名前 | コマンドの名前(コンソールから起動するために使用されます) |
| ISPublic | 本当なら、それはコンソール情報に表示されます |
| モード | オンデマンドにすることができます、 |
| 注文 | 非デマンド、beforecommand、またはaftercommandの実行命令。 On Deamandオプションはデフォルトのオプションであり、おそらくあなたが通常何をしているかです。コマンドは、ユーザーがコマンドラインから実行しない限り、何もしません。モードの前と前にコマンドを実行すると、 ondemandコマンドを実行します。たとえば、「ウェルカム」または「閉じる鍵」は、イベントの前後です。 |
このツールは、一連のアクションを実行するために使用できます。このモードでは、多くの原子コマンドを定義し、外部ファイルを使用してシーケンスを定義できます。
設定ファイルmyscript.yaml
Commands :
welcome_step1 :
Action : welcome
Desctiption : This is the line of text that will shown first
Args :
header : my text (first line)
welcome_step2 :
Action : welcome
Desctiption : In this example we do it twice, to prove we can execute commands multiple times with different args.
Args :
header : my text (second line)
main_step :
Action : CommandOne
Desctiption : This is a custom command that diplay the test. Yes, another dummy thing.
Args :
text : I'm the central command output!
State :
text : myglobal
MyExec.exe exec MyScript.yamlこのライブラリは、MITライセンスの期間に基づいてリリースされます。
このソフトウェアは、商品性、特定の目的への適合性、および非侵害の保証を含むがこれらに限定されない、明示的または黙示的なものを保証することなく、「現状のまま」提供されます。いかなる場合でも、著者または著作権所有者は、契約、不法行為、またはその他の訴訟、ソフトウェアまたはソフトウェアの使用またはその他の取引に関連する、またはその他の契約、またはその他の請求、またはその他の責任について責任を負いません。
FlaticonのEucalypが作成したアイコン