Command line¶
Note
The documentation in this section is aimed at people wishing to contribute to
versionah
, and can be skipped if you are simply using the tool from the
command line.
-
class
versionah.cmdline.
NameParamType
[source]¶ Name parameter handler.
Initialise a new
ReMatchParamType
object.
-
class
versionah.cmdline.
ReMatchParamType
[source]¶ Regular expression based parameter matcher.
Initialise a new
ReMatchParamType
object.-
convert
(value, param, ctx)[source]¶ Check given name is valid.
- Parameters
value (str) – Value given to flag
param (click.Argument) – Parameter being processed
ctx (click.Context) – Current command context
- Returns
Valid value
- Return type
-
-
class
versionah.cmdline.
VersionParamType
[source]¶ Version parameter handler.
Initialise a new
ReMatchParamType
object.
-
class
versionah.cmdline.
CliVersion
(components=(0, 1, 0), name='unknown', date=datetime.date(2019, 11, 7))[source]¶ Specialisation of models.Version for command line usage.
Initialise a new
Version
object.- Parameters
components (str) – Version components
name (str) – Package name
date (datetime.date) – Date associated with version
-
static
read
(filename)[source]¶ Read a version file.
- Parameters
filename (str) – Version file to read
- Returns
New
CliVersion
object representing file- Return type
- Raises
OSError
– Whenfilename
doesn’t existValueError
– Unparsable version data
-
versionah.cmdline.
guess_type
(filename)[source]¶ Guess output type from filename.
- Parameters
filename (str) – File to operate on
-
versionah.cmdline.
cli
(*args, **kwargs)¶ Main command entry point.
-
versionah.cmdline.
bump
(*args, **kwargs)¶ Bump version in existing file.
-
versionah.cmdline.
display
(*args, **kwargs)¶ Display version in given file.
-
versionah.cmdline.
set_version
(*args, **kwargs)¶ Set version in given file.
Examples¶
Reading version data from a file¶
>>> CliVersion.read('tests/data/test_a')
CliVersion((0, 1, 0), 'test', datetime.date(2011, 2, 19))
>>> CliVersion.read('tests/data/test_b')
CliVersion((1, 0, 0), 'test', datetime.date(2011, 2, 19))
>>> CliVersion.read('tests/data/test_c')
CliVersion((2, 1, 3), 'test', datetime.date(2011, 2, 19))
Writing version date to a file¶
>>> v = CliVersion((0, 1, 0), 'test', datetime.date(2011, 2, 19))
>>> v.write('test_data.python', 'py') # doctest: +SKIP
>>> v.write('test_data.hh', 'h') # doctest: +SKIP
>>> v.write('test_data.m4', 'm4') # doctest: +SKIP
Guess file type from name¶
>>> guess_type('main.c')
'c'
>>> guess_type('version.py')
'py'
>>> guess_type('no_suffix')
'text'
>>> guess_type('suffix.unknown')
'text'