省略可能な引数の配置について

hexo new [layout] <title>

テーマを色々と見ていて、ふと気がついた。 hexo new post とした時にタイトルが post になっていた理由に。

newhelp を改めてみてみる。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ hexo help new
Usage: hexo new [layout] <title>

Description:
Create a new post.

Arguments:
  layout  Post layout. Use post, page, draft or whatever you want.
  title   Post title. Wrap it with quotations to escape.

Options:
  -p, --path     Post path. Customize the path of the post.
  -r, --replace  Replace the current post if existed.
  -s, --slug     Post slug. Customize the URL of the post.

あー、なるほど。

layout が省略可能扱いなので、 hexo new post とした場合、 postlayout ではなく title として入力されていた、という話だった。

ふと気がついた、わけではない

実際には、テーマの使い方の説明のところに hexo new <title> と書いてあったのを見て、もしかして、と思った。 で、調べてみたところ案の定、って感じ。

コマンド体系

ところで、最近のコマンドはサブコマンド形式が多い。

普段お世話になっている brew もそうだし、この hexo もそう。

また、サブコマンドを入力しなかった時に使い方がでる、というスタイルや、 コマンド help サブコマンド のようにしてサブコマンドのヘルプを呼び出す、というのもだいたい共通している。

また、上の方では hexo help new として結果を書いているが、 hexo new でも同じ内容のヘルプが出る。

ターミナル上で操作をしていると、新しいコマンドもとりあえず同じように使ってみる、ということがあると思う。

取扱説明書を熟読してから家電を使う人はいない。

コマンドもそうだと思う。

ヘルプを見なくても使えるコマンドは素晴らしいコマンドだ。

plenv のような、 **env は沢山ある。

anyenv を使うと、そのような **env が気軽に使えるようになる。

しかし、時々コマンド体系が違うものがあって嫌な感じになる。

例えば goenv に関しては、インストール可能なバージョンを確認しようとして goenv install -l とするとエラーになる。

で、 goenv install ではどうかというと、以下のようになる。

1
2
3
$ goenv install
/Users/nobu/.anyenv/envs/goenv/libexec/goenv-install: line 18: [: =: unary operator expected
Not found:

ちなみに、 plenv ではどうかというと。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
$ plenv install

Summary: Install a Perl version using the perl-build plugin

Usage: plenv install [-v|--verbose] <version>
       plenv install [-v|--verbose] /path/to/definition
       plenv install -l|--list

  -l/--list        List all available versions
  -v/--verbose     Verbose mode: print compilation status to stdout
  --as=<NAME>      Install the definition as <NAME>
  --test           Run test cases
  --noman          Skip installation of manpages
  -D, -A, -U, -j   perl configure options via perl-build

Example:
  plenv install 5.20.2 -j 8 -Dcc=gcc -UDEBUGGING -Accflags=...

For more options that are passed through perl-build, run `perl-build --help`
or see: https://metacpan.org/pod/distribution/Perl-Build/script/perl-build#OPTIONS

なお、 goenv でインストール可能なバージョンの一覧は goenv install --list で見ることができるのだが、ヘルプにも書いていない…。

1
2
3
4
$ goenv help install
Usage: goenv install <version>

Versions should be in the form of N.N.N

とはいえ、実際のところ、golangの場合は実行形式で配布できるので、言語自体のバージョンを固定したり切り替えたりする意味もなさそうではある。

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy