charlesdaniels / bitshuffle

BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

Encode command line arguments #16

Open jyn514 opened 6 years ago

jyn514 commented 6 years ago

Currently, adding extra arguments gives a usage error. It would be nice to take additional arguments to encode.

charlesdaniels commented 6 years ago

Can you elaborate a little bit on what you are looking to do? Are you referring To the argparse arguments?

Can you show an example of the error?

jyn514 commented 6 years ago

Currently:

joshua@debian-thinkpad:/usr/local/src/bitshuffle$ ./bitshuffle.py -e some message here
usage: bitshuffle.py [-h] [--input INPUT] [--output OUTPUT]
                 [--filename FILENAME] [--encode] [--decode] [--version]
                 [--chunksize CHUNKSIZE] [--compresslevel COMPRESSLEVEL]
                 [--editor EDITOR] [--compresstype COMPRESSTYPE]
bitshuffle.py: error: unrecognized arguments: some message here

After this has been added:

joshua@debian-thinkpad:/usr/local/src/bitshuffle$ ./bitshuffle.py -e some message here
((<<This is encoded with BitShuffle, which you can download from https://github.com/charlesdaniels/bitshuffle|1|base64|bz2|0|0|stdin|9477a94f13fef4343e1fca75a1a814f870160dc6|QlpoNTFBWSZTWdy1BSkAAAhRgAAQQAAiwpgAIAAxADAp6A9JP28BA1onHC7kinChIblqClI=>>))
charlesdaniels commented 6 years ago

Argparse does have the functionality you’re after. There is a way to make it accept arbitrary positional arguments to a parameter.

charlesdaniels commented 6 years ago

I actually implemented a similar feature for a tiny script I wrote for another project recently. link]

For this to work, we need to move away from having everything run on file handles. I propose we add a wrapper class which can contain any of:

The wrapper class should be set up with __iter__ (?) so that we can do for line in thing and have it work right. We can also use this wrapper to abstract out the Python 2.x and 3.x differences.

The class's constructor should take either a file-like or a list-of-strings and handle setting up it's internal state appropriately.