Skip to content

Commit 59427dc

Browse files
authored
Merge pull request #12 from kernelshard/feature/version-flag
feat: add version flag to CLI
2 parents 3c4050c + dcd3b31 commit 59427dc

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Samiul Sk
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ expose tunnel
4242

4343
## 📖 Usage
4444

45+
### Version
46+
47+
Check the version of expose:
48+
49+
```
50+
expose --version
51+
# expose version v0.1.1 (commit: 4784595, built: 2025-11-07)
52+
```
53+
4554
### Initialize Project
4655

4756
Create a `.expose.yml` configuration file:
@@ -129,6 +138,12 @@ Contributions welcome! This project follows:
129138
- Commit message format: `type: description`
130139
- Clean, tested, documented code
131140

141+
### Contributors
142+
143+
- **Samiul Sk** - Project creator and maintainer
144+
145+
*Want to contribute? See our [contributing guidelines](CONTRIBUTING.md) (coming soon)*
146+
132147
## 📝 License
133148

134149
MIT License - see [LICENSE](LICENSE) for details.

internal/cli/root.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package cli
22

33
import (
44
"github.com/spf13/cobra"
5+
6+
"github.com/kernelshard/expose/internal/version"
57
)
68

79
var rootCmd = &cobra.Command{
8-
Use: "expose",
9-
Short: "Expose localhost to the internet",
10-
Long: "Minimal CLI to expose your local dev server",
10+
Use: "expose",
11+
Short: "Expose localhost to the internet",
12+
Long: "Minimal CLI to expose your local dev server",
13+
Version: version.GetFullVersion(),
1114
}
1215

1316
func Execute() error {

internal/version/version.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package version
2+
3+
var (
4+
Version = "v0.1.1"
5+
GitCommit = "4784595"
6+
BuildDate = "2025-11-07"
7+
)
8+
9+
// GetVersion returns just the version string
10+
func GetVersion() string {
11+
if Version == "dev" {
12+
return "dev (unreleased)"
13+
}
14+
return Version
15+
}
16+
17+
// GetFullVersion returns version with build metadata (for Cobra)
18+
// Note: Cobra automatically prefixes with "expose version"
19+
func GetFullVersion() string {
20+
return GetVersion() + " (commit: " + GitCommit + ", built: " + BuildDate + ")"
21+
}

internal/version/version_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package version
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func TestGetVersion(t *testing.T) {
9+
v := GetVersion()
10+
if !strings.Contains(v, Version) {
11+
t.Errorf("GetVersion mismatch expected %s in:%s", Version, v)
12+
}
13+
}
14+
15+
func TestGetFullVersion(t *testing.T) {
16+
fullVersion := GetFullVersion()
17+
if !strings.Contains(fullVersion, GitCommit) {
18+
t.Errorf("GetFullVersion call expected %s in %s", GitCommit, fullVersion)
19+
}
20+
if !strings.Contains(fullVersion, BuildDate) {
21+
t.Errorf("GetFullVersion call expected %s in %s", BuildDate, fullVersion)
22+
}
23+
}

0 commit comments

Comments
 (0)