Skip to content

Commit d3aeb8c

Browse files
committed
Add version tagging
1 parent 2da590b commit d3aeb8c

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-7
lines changed

Justfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
DATE := `date +"%Y-%m-%d_%H:%M:%S"`
2+
GIT_COMMIT := `git rev-parse HEAD`
3+
VERSION_TAG := `git describe --tags --abbrev=0`
4+
LD_FLAGS := "-X github.com/chand1012/ottodocs/cmd.buildDate=" + DATE + " -X github.com/chand1012/ottodocs/cmd.commitHash=" + GIT_COMMIT + " -X github.com/chand1012/ottodocs/cmd.tag=" + VERSION_TAG
5+
16
default:
27
just --list --unsorted
38

49
tidy:
510
go mod tidy
611

712
build:
8-
go build -v -o bin/otto
13+
go build -ldflags "{{LD_FLAGS}}" -v -o bin/otto
914

1015
clean:
1116
rm -rf bin dist
@@ -18,6 +23,7 @@ cobra-docs:
1823
go run docs/gen_docs.go
1924

2025
install: build
26+
rm -rf $GOPATH/bin/otto
2127
cp bin/otto $GOPATH/bin
2228

2329
crossbuild:
@@ -31,35 +37,35 @@ crossbuild:
3137

3238
# Build for M1 Mac (Apple Silicon)
3339
echo "Building for M1 Mac (Apple Silicon)"
34-
env GOOS=darwin GOARCH=arm64 go build -o "${BINARY_NAME}" "${GO_PACKAGE}"
40+
env GOOS=darwin GOARCH=arm64 go build -ldflags "{{LD_FLAGS}}" -o "${BINARY_NAME}" "${GO_PACKAGE}"
3541
zip "${BINARY_NAME}_darwin_arm64.zip" "${BINARY_NAME}"
3642
rm "${BINARY_NAME}"
3743
mv "${BINARY_NAME}_darwin_arm64.zip" dist/
3844

3945
# Build for AMD64 Mac (Intel)
4046
echo "Building for AMD64 Mac (Intel)"
41-
env GOOS=darwin GOARCH=amd64 go build -o "${BINARY_NAME}" "${GO_PACKAGE}"
47+
env GOOS=darwin GOARCH=amd64 go build -ldflags "{{LD_FLAGS}}" -o "${BINARY_NAME}" "${GO_PACKAGE}"
4248
zip "${BINARY_NAME}_darwin_amd64.zip" "${BINARY_NAME}"
4349
rm "${BINARY_NAME}"
4450
mv "${BINARY_NAME}_darwin_amd64.zip" dist/
4551

4652
# Build for AMD64 Windows
4753
echo "Building for AMD64 Windows"
48-
env GOOS=windows GOARCH=amd64 go build -o "${BINARY_NAME}.exe" "${GO_PACKAGE}"
54+
env GOOS=windows GOARCH=amd64 go build -ldflags "{{LD_FLAGS}}" -o "${BINARY_NAME}.exe" "${GO_PACKAGE}"
4955
zip "${BINARY_NAME}_windows_amd64.zip" "${BINARY_NAME}.exe"
5056
rm "${BINARY_NAME}.exe"
5157
mv "${BINARY_NAME}_windows_amd64.zip" dist/
5258

5359
# Build for AMD64 Linux
5460
echo "Building for AMD64 Linux"
55-
env GOOS=linux GOARCH=amd64 go build -o "${BINARY_NAME}" "${GO_PACKAGE}"
61+
env GOOS=linux GOARCH=amd64 go build -ldflags "{{LD_FLAGS}}" -o "${BINARY_NAME}" "${GO_PACKAGE}"
5662
tar czvf "${BINARY_NAME}_linux_amd64.tar.gz" "${BINARY_NAME}"
5763
rm "${BINARY_NAME}"
5864
mv "${BINARY_NAME}_linux_amd64.tar.gz" dist/
5965

6066
# Build for ARM64 Linux
6167
echo "Building for ARM64 Linux"
62-
env GOOS=linux GOARCH=arm64 go build -o "${BINARY_NAME}" "${GO_PACKAGE}"
68+
env GOOS=linux GOARCH=arm64 go build -ldflags "{{LD_FLAGS}}" -o "${BINARY_NAME}" "${GO_PACKAGE}"
6369
tar czvf "${BINARY_NAME}_linux_arm64.tar.gz" "${BINARY_NAME}"
6470
rm "${BINARY_NAME}"
6571
mv "${BINARY_NAME}_linux_arm64.tar.gz" dist/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
44

5-
OttoDocs is a command-line tool written in Go that uses GPT-3 (and GPT-4 once the API is available) to automatically generate or add inline and markdown documentation for your code. It can parse a git repository or an individual file and create markdown documentation or add inline comments. The tool requires an [OpenAI API key](https://platform.openai.com/account/api-keys) to function.
5+
OttoDocs is a command-line tool written in Go that uses ChatGPT to automatically generate or add inline and markdown documentation for your code. It can parse a git repository or an individual file and create markdown documentation or add inline comments. The tool requires an [OpenAI API key](https://platform.openai.com/account/api-keys) to function.
66

77
OttoDocs utilizes the `just` command runner for building and running tasks, making maintaining the project easier. If you do not have `just` installed, see [here](https://just.systems/man/en/chapter_5.html) for installation methods.
88

cmd/version.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"strings"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var commitHash string
14+
var buildDate string
15+
var tag string
16+
17+
// versionCmd represents the version command
18+
var versionCmd = &cobra.Command{
19+
Use: "version",
20+
Short: "Prints version information.",
21+
Long: `Prints version information.`,
22+
Run: func(cmd *cobra.Command, args []string) {
23+
fmt.Println("ottodocs")
24+
fmt.Println("commit hash:", commitHash)
25+
fmt.Println("build date:", strings.ReplaceAll(buildDate, "_", " "))
26+
fmt.Println("version:", tag)
27+
},
28+
}
29+
30+
func init() {
31+
RootCmd.AddCommand(versionCmd)
32+
}

docs/otto.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ Code documentation made easy using GPT.
1717
* [otto ask](otto_ask.md) - Ask a question about a file or repo
1818
* [otto chat](otto_chat.md) - Ask ChatGPT a question from the command line.
1919
* [otto cmd](otto_cmd.md) - Have ChatGPT suggest a command to run next
20+
* [otto commit](otto_commit.md) - Generates a commit message from the git diff
2021
* [otto docs](otto_docs.md) - Document a repository of files or a single file
2122
* [otto login](otto_login.md) - Add an API key to your configuration
2223
* [otto prompt](otto_prompt.md) - Generates a ChatGPT prompt from a given Git repo
2324
* [otto setModel](otto_setModel.md) - Set the model to use for documentation
25+
* [otto version](otto_version.md) - Prints version information.
2426

2527
###### Auto generated by spf13/cobra on 21-Apr-2023

docs/otto_commit.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## otto commit
2+
3+
Generates a commit message from the git diff
4+
5+
### Synopsis
6+
7+
Uses the git diff to generate a commit message. Requires Git to be installed on the system.
8+
9+
```
10+
otto commit [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-c, --conventional use conventional commits
17+
-h, --help help for commit
18+
-p, --plain no output formatting
19+
```
20+
21+
### SEE ALSO
22+
23+
* [otto](otto.md) - Document your code with ease
24+
25+
###### Auto generated by spf13/cobra on 21-Apr-2023

docs/otto_version.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## otto version
2+
3+
Prints version information.
4+
5+
### Synopsis
6+
7+
Prints version information.
8+
9+
```
10+
otto version [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help help for version
17+
```
18+
19+
### SEE ALSO
20+
21+
* [otto](otto.md) - Document your code with ease
22+
23+
###### Auto generated by spf13/cobra on 21-Apr-2023

0 commit comments

Comments
 (0)