There was a messy point in my Python script: Brew-file, related with ArgumentParser.
In this post, the problem and how I addressed are written.
parse_known_args in ArgumentParser
ArguentParser is a module to analyze arguments, like this:
1 2 3 4 5 6 | |
In the script, if it is called without argument, it returns the arguments to the script in the form of Namespace object.
If other values than what are defined by add_argument,
it gives an error:
1 2 3 | |
If you want to give such file names,
and want to use variadic arguments,
use parse_known_args instead of parse_args.
1 2 3 4 5 | |
parse_known_args returns the analyzed results
and remaining arguments as an array.
ArgumentParser’s subparsers
ArgumentParser has a function of subparsers.
1 2 3 4 5 6 7 8 9 | |
Like this, if it finds subperser, it starts child parsing for bbb.
Here, in Python 2.7.7 and later,
if unknown arguments are given,
parse_known_args can analyze as above.
But for Python 2.7.6 and earlier, it shows an error:
1 2 3 | |
The problem is that OS X Yosemite’s default Python is 2.7.6.
And Brew-file’s brew command uses this function.
Therefore, if you want to use brew file brew command,
you need to install Python 2.7.7 or later, or Python 3.X.
Fix at Brew-file
Actually, it affects only on brew command in Brew-file.
Therefore, I ignore it for now in Brew-file.
(It will give an error if you use brew command with Python 2.7.6.)
In addition, /etc/brew-wrap wraps default brew command.
For such brew install command, it wraps as brew file brew install ....
It should not be used with Python 2.7.6, therefore the wrapper function was modified for that it wraps only when newer Python is available.
