1

私は最近、プロジェクトを Picocli 4.2.0 にアップグレードしました。これには、廃止されたすべてのメソッド呼び出しの削除が含まれており、ここで説明した作業を続けています。私は再び同じ問題に直面しています - リセットされないように見えるフィールドがあります。これが私の他の質問と異なる唯一のことは、フィールドがコレクションになったことです。コードは次のようになります。

@Command(name="watch", description="Alters the set of watched productions", subcommands={HelpCommand.class})
static public class Watch implements Runnable
{
    @ParentCommand
    ProductionC parent; // injected by picocli

    @Option(names={"on", "-e", "--on", "--enable"}, description="Enables watching of given productions")
    List<String> productionsToEnable;

    @Option(names={"off", "-d", "--off", "--disable"}, description="Disables watching of given productions")
    List<String> productionsToDisable;

    @Override
    public void run()
    { ... }

(完全なコードはこちらから入手できます。)

具体的には、productionsToEnableリセットされないようです。呼び出しが行われる方法は、単体テストの一部です。

@Test
public void testCanListTracedRules() throws Exception
{
    loadRules();
    agent.getInterpreter().eval("production watch --on b");
    agent.getInterpreter().eval("production watch --on c");

    final StringWriter result = new StringWriter();
    agent.getPrinter().pushWriter(result);
    agent.getInterpreter().eval("production watch");
    agent.getPrinter().popWriter();
    assertEquals("b\nc", result.toString());
}

(完全なコードはこちらから入手できます。)

"c"最後の への呼び出しの文字列は、最後の でコマンドが呼び出されたときにproduction watchまだ存在しています。productionsToEnableproduction watcheval

上記のコード リンクはjsoar-command-performanceブランチ上にあることに注意してください。詳細を確認するのに役立ちます。

4

1 に答える 1