在PicoCli中显示定制的帮助?

我有一个用例,我需要以指定格式发布CLI的整个帮助。我找到了一种使用以下方法做到这一点的方法:

<table id="dtBasicExample" class="table table-striped table-bordered table-sm  table table-condensed" cellspacing="0" width="100%" style="border-collapse:collapse;">
  <thead>
    <tr>
      	<th class="th-sm">Sport Id</th>
    	<th class="th-sm">Gender</th>
    	<th class="th-sm">Location</th>
    	<th class="th-sm">Country</th>
    	<th class="th-sm">State</th>
    	<th class="th-sm">City</th>
    	<th class="th-sm">action</th>

    </tr>
  </thead>
  <tbody>
   @foreach ($challenges as $challenge)
        <tr data-toggle="collapse" data-target="#demo1" class="accordion-toggle">
                  <td><button class="btn btn-default btn-xs"><span class="glyphicon glyphicon-eye-open"></span></button></td>
        	<td>{{$challenge->c_sport_id}}</td>
        	<td>{{$challenge->c_gender_id}}</td>
        	<td>{{$challenge->c_location}}</td>
        	<td>{{$challenge->c_country_id}}</td>
        	<td>{{$challenge->c_state_id}}</td>
        	<td>{{$challenge->c_city_id}}</td>
       
    	<div colspan="12" class="hiddenRow"><div class="accordian-body collapse" id="demo1"> 
        	sport{{$challenge->c_sport_id}}
gender{{$challenge->c_gender_id}}
location{{$challenge->c_location}}
country{{$challenge->c_country_id}}
state{{$challenge->c_state_id}}
city{{$challenge->c_city_id}}
date{{$challenge->c_date}}
desc{{$challenge->c_desc}}
time{{$challenge->c_time}}
invite{{$challenge->c_invite}}
refree{{$challenge->c_refree_id}}</div>
  
        	<td><a rel="tooltip" title="" class="btn btn-simple btn-danger btn-icon table-action remove" href="javascript:void(0)" data-original-title="Remove"><i class="ti-pencil"></i></a>
           <a rel="tooltip" title="" class="btn btn-simple btn-danger btn-icon table-action remove" href="javascript:void(0)" data-original-title="Remove"><i class="ti-close"></i></a>
           
           </td>
        	</tr>
    @endforeach
  </tbody>
  <tfoot>
    <tr>
      <th>sport_id
      </th>
      <th>gender_id
      </th>
      <th>location
      </th>
      <th>country
      </th>
      <th>state
      </th>
      <th>city
      </th>
      <th>action
      </th>
    </tr>
  </tfoot>
</table>

如果用户输入-h或--help,则帮助将以我想要的格式打印出来;如果他们没有输入-h或-H,则不会。

有更好的方法吗?

如果以后再添加其他命令,那么添加它们的人都必须记住要更新帮助字符串。

wsw123wsw1 回答:在PicoCli中显示定制的帮助?

您的解决方案可以工作,但有一个缺点(如您提到的那样),用法帮助消息是静态的,不会反映将来的更新,例如添加了新的子命令或选项。

Picocli确实提供了一种通过其Help API动态自定义使用帮助消息的方法。这使您可以对使用帮助消息中的部分进行重新排序或替换。我相信您要替换的部分是command list section

这需要深入研究picocli使用帮助模型。为了帮助您入门,picocli-examples模块提供了一些自定义帮助示例。 This example显示了如何修改用法帮助消息以显示完整的命令层次结构(尽管没有选项),这与您要执行的操作相当接近。您可以以此为起点。如果您还有其他问题,请随时在picocli github问题跟踪器(或此处)上举票。

本文链接:https://www.f2er.com/3047190.html

大家都在问