automatically setting version in code with cvs
- automatically setting version in code with cvs
I maintain a lot of code/scripts/packages/modules with version control. It's really useful to have automatic versioning of something.
What am I talking about?
There are certain things a command line interface program (a command) should do. One is, there has to ve a -h or --help flag to get basic help.
Another thing- is that somehow it should be able to tell you what the version is. This may be inside the help output, or it may be triggered by the -h or --help option.
If you're using some kind of version control system ( which you should- and if you don't, then stop reading and go figure out basic cvs usage. ), there are several special strings that you put in your code that will automatically be updated by cvs.
One of them is '$Revision:$', this gets automatically updated every time you commit a change to such file in cvs.
This way, you never have to change the version number in your code by hand. You can have cvs automatically do this. This is useful if you want to keep up to date the date and version of last changes - in your pod documentation, in a perl script.. shell script.. etc.
our $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)/g;
- vim abbreviation
iab plv- our $VERSION = sprintf "%d.%02d", q$Revision: 1.0 $ =~ /(\d+)/g;
VERSION=$(printf "%d.%02d" $(echo '$Revision: 1.6 $' | sed 's/\$\|Revision:\|\./ /g'))
- vim abbreviation
iab shv- VERSION=$(printf "%d.%02d" $(echo '$Revision: 1.6 $' <bar> sed 's/\$\<bar>Revision:\<bar>\./ /g'))
I hate trying to remember the code lines shown. It sucks. That's not what people were made to do. Computers were made to do these things- so .. The abbreviations. You can have the abbreviations available to you by putting these lines in your .vimrc file..
iab shv- VERSION=$(printf "%d.%02d" $(echo '$Revision: 1.6 $' <bar> sed 's/\$\<bar>Revision:\<bar>\./ /g')) iab plv- our $VERSION = sprintf "%d.%02d", q$Revision: 1.0 $ =~ /(\d+)/g;
So when you type out plv- and a whitespace character (space, tab, return (newline) etc.. ) You'll get the expansion you want. You may want to read more about vim abbreviations, I wrote a small program to help in creating them from text blurbs.