Add --version flag to the executable

This commit is contained in:
Alessio 2022-01-04 12:57:43 -05:00
parent a23d3b98e7
commit e06b0bff30
4 changed files with 28 additions and 7 deletions

View File

@ -122,8 +122,12 @@ tasks:
twitter fetch_user michaelmalice twitter fetch_user michaelmalice
twitter get_user_tweets michaelmalice twitter get_user_tweets michaelmalice
# Compile the binary with the version number
cd .. && ./compile.sh $version
cd outdated_profile
# Now test the upgrade using the newer version # Now test the upgrade using the newer version
which ../tw # Should be here from previous step which ../tw
../tw fetch_user michaelmalice # Any operation other than `create_profile` should trigger the upgrade ../tw fetch_user michaelmalice # Any operation other than `create_profile` should trigger the upgrade
duration=$SECONDS duration=$SECONDS

View File

@ -3,5 +3,9 @@
set -x set -x
set -e set -e
go build -ldflags="-s -w" -o tw ./twitter if [[ -n "$1" ]]; then
go build -ldflags="-s -w -X main.version_string=$1" -o tw ./twitter
else
go build -ldflags="-s -w" -o tw ./twitter
fi
chmod +x tw chmod +x tw

View File

@ -5,12 +5,15 @@ set -x
PS4='+(${BASH_SOURCE}:${LINENO}): ' PS4='+(${BASH_SOURCE}:${LINENO}): '
./compile.sh FAKE_VERSION="1.100.3489"
./compile.sh $FAKE_VERSION
test -e data && rm -r data test -e data && rm -r data
PATH=`pwd`:$PATH PATH=`pwd`:$PATH
test "$(tw --version)" = "v$FAKE_VERSION"
tw create_profile data tw create_profile data
cd data cd data

View File

@ -13,19 +13,29 @@ import (
*/ */
var profile persistence.Profile var profile persistence.Profile
var version_string string
/** /**
* Main method * Main method
*/ */
func main() { func main() {
if len(os.Args) < 3 {
die("", true, 0)
}
profile_dir := flag.String("profile", ".", "TODO USAGE") profile_dir := flag.String("profile", ".", "TODO USAGE")
flag.StringVar(profile_dir, "p", ".", "TODO USAGE")
show_version_flag := flag.Bool("version", false, "???")
flag.BoolVar(show_version_flag, "v", false, "???")
flag.Parse() flag.Parse()
args := flag.Args() args := flag.Args()
if *show_version_flag {
if version_string == "" {
fmt.Println("Development version")
} else {
fmt.Println("v" + version_string)
}
os.Exit(0)
}
if len(args) < 2 { if len(args) < 2 {
die("", true, 1) die("", true, 1)
} }