命令行选项:应该将短选项限制为 1 个字符吗? [英] Command-line Options: Should short options be restricted to 1 character?

查看:21
本文介绍了命令行选项:应该将短选项限制为 1 个字符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解 Python 的命令行参数,并且一直在阅读有关 argparse 模块.他们提到了短格式和长格式命令行选项的概念,短格式选项用单个破折号指定,-(例如 -f),并指定长格式选项带有两个破折号,--(例如 --filename).

I'm trying to get my head around command-line arguments for Python and have been reading the Standard Library documentation about the argparse module. They mention the concept of short and long form command-line options, with short form options specified with a single dash, - (eg -f), and long form options specified with two dashes, -- (eg --filename).

没有任何地方描述短格式和长格式选项之间的区别,只是一个明显比另一个短.在谷歌搜索概念后,在我看来,短格式选项起源于很久以前的 C.当时它们是一个字符.

Nowhere does it describe the difference between the short form and long form options, except that one is obviously shorter than the other. After Googling the concepts it seems to me short form options originated long ago in C. Back then they were a single character.

我的问题是,在 Python 中,我是否应该继续只使用单个字符作为短格式命令行选项?这是用户所期望的吗?或者是否可以在短选项中使用三个字符中的两个缩写(例如 -fn)?

My question is, should I continue to use only a single character for short form command-line options in Python? Is that what users will expect? Or is it acceptable to use two of three character abbreviations in the short options (eg -fn)?

推荐答案

我相信我们可以参考 POSIX 标准和 GNU 编码指南.尽管没有某种全球"标准,但我想我们至少在为 *nix 编码时应该坚持这些规则.

I believe we could make a reference for POSIX standard and GNU coding guidelines. Despite there isn't a sort of 'global' standard, I suppose we should stick to these rules at least while we code for *nix.

根据 POSIX 约定,每个选项名称应为可移植字符集中的单个字母数字字符(alnum 字符分类).并且所有选项都应以-"分隔符开头.

According to the POSIX conventions each option name should be a single alphanumeric character (the alnum character classification) from the portable character set. And all options should be preceded by the '-' delimiter character.

GNU 指南增加了long选项

长选项由 -- 后跟由字母数字字符和破折号组成的名称组成.选项名称通常为一到三个单词长,用连字符分隔单词.只要缩写是唯一的,用户就可以缩写选项名称.

Long options consist of -- followed by a name made of alphanumeric characters and dashes. Option names are typically one to three words long, with hyphens to separate words. Users can abbreviate the option names as long as the abbreviations are unique.

这篇关于命令行选项:应该将短选项限制为 1 个字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆