#274·docopt

How to specify default value for argument?

Author: mcandreCreated May 1, 2015Updated Feb 27, 2026

Summary

How do I specify a default for an argument?

DOCOPT

Usage:
  aspelllint [-i <pattern>]... [<file>]...
  aspelllint -v | --version
  aspelllint -h | --help

Arguments:
  <file>                 Filename, or - for stdin [default: -]

Options:
  -i --ignore <pattern>  Ignore file pattern (fnmatch)
  -v --version           Print version info
  -h --help              Print usage info

Steps to reproduce

$ brew install aspell
$ git clone [email protected]:mcandre/aspelllint.git
$ cd aspellint/
$ git checkout docopt
$ bundle install
$ rake install
$ aspelllint < examples/toy-boats.txt

Expected

{"--ignore"=>nil, "<file>"=>['-'], "--version"=>false, "--help"=>false}

Observed

{"--ignore"=>nil, "<file>"=>[], "--version"=>false, "--help"=>false}

Source

https://github.com/mcandre/aspelllint/blob/dc607223c3218cbd9d9c40a3c673da22060c7d78/lib/cli.rb

System

$ specs gem:docopt ruby chruby mrvm brew os
Specs:

specs 0.18
https://github.com/mcandre/specs#readme

gem list | grep docopt
docopt (0.5.0)

bundle --version
Bundler version 1.8.3

gem --version
2.4.6

ruby --version
ruby 2.0.0p598 (2014-11-13 revision 48408) [x86_64-darwin14.1.0]

chruby --version
chruby: 0.3.9

mrvm --version
rvm 1.26.10 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

brew --version
0.9.5

system_profiler SPSoftwareDataType | grep 'System Version'
    System Software Overview:
      System Version: OS X 10.10.3 (14D136)