Я хочу иметь возможность установить строку Usage
, чтобы указать, что аргумент НУЖЕН быть передан, если функция справки вызывается по команде кобры в Go.
Это то, что является обычным флагом справки.вывод:
Cancel the order specified by the order id by submitting a cancel order.
Optionally, an account ID may be supplied as well for extra measure.
Usage:
gbutil orders cancel [flags]
Flags:
-a, --account_id string the account id that the order belongs to
-h, --help help for cancel
Global Flags:
--config string config file (default is $HOME/.gbutil.yaml)
Я хочу:
Cancel the order specified by the order id by submitting a cancel order.
Optionally, an account ID may be supplied as well for extra measure.
Usage:
gbutil orders cancel <order_id> [flags]
Flags:
-a, --account_id string the account id that the order belongs to
-h, --help help for cancel
Global Flags:
--config string config file (default is $HOME/.gbutil.yaml)
Я попытался использовать SetUsageTemplate
в функции init()
, но затем он удаляет часть флагов:
orderscancelCmd.SetUsageTemplate(strings.Replace(orderscancelCmd.UsageString(), "gbutil orders cancel [flags]", "gbutil orders cancel <order_id> [flags]", 1))
В результате:
Cancel the order specified by the order id by submitting a cancel order.
Optionally, an account ID may be supplied as well for extra measure.
Usage:
gbutil orders cancel <order_id> [flags]
Flags:
-a, --account_id string the account id that the order belongs to
, где я теряю флаг -h
и дополнительную информацию о Global Flags
.
Я могу заставить его работать, если они неВы можете получить аргумент:
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
fmt.Println(strings.Replace(cmd.UsageString(), "gbutil orders cancel [flags]", "gbutil orders cancel <order_id> [flags]", 1))
return
}
, но затем флаг -h
по-прежнему выводит неверную строку использования.
Есть ли способ сделать это?Заранее спасибо!