I had this idea of generating version information for a Python script that uses ArgParse. The code is a little more than I was expecting but I think it works well. Here is the code:
Usage
Here is an example of its usage if the script is part of a git repository:
$ ./version-example --version b92798, master, 2019-01-18 10:35:02, ['origin:https://github.com/pfuntner/gists.git'] $
It contains:
- The SHA1 of last git commit that changed the script
- The current branch of the repository
- The date of the commit - I think the timezone element is present in this but I didn't want to deal with timezones so I'm ignoring it
- A list of the remote repositories
This is printed on two lines but that's something that ArgParse is doing, not me.
Here is an example of its usage if the script is not part of a git repository - we don't have much information to work from but we can at least get the timestamp of the script:
$ ~/tmp/version-example --version 2019-01-18 11:07:33.873846 $
You'll also get this output if the script is in the repository directory but hasn't been committed to it.
Comments
Post a Comment