fix: show version number

This commit is contained in:
2025-01-14 00:27:59 +02:00
parent 605c733691
commit d62c643be9
5 changed files with 38 additions and 20 deletions

View File

@@ -109,13 +109,14 @@ sofmani my-config.yaml
The following flags are supported to customize behavior:
| Flag | Description |
| ------------------- | ---------------------------------- |
| `-d`, `--debug` | Enable debug mode. |
| `-D`, `--no-debug` | Disable debug mode (default). |
| `-u`, `--update` | Enable update checking. |
| `-U`, `--no-update` | Disable update checking (default). |
| `-h`, `--help` | Display help information and exit. |
| Flag | Description |
| ------------------- | ------------------------------------- |
| `-d`, `--debug` | Enable debug mode. |
| `-D`, `--no-debug` | Disable debug mode (default). |
| `-u`, `--update` | Enable update checking. |
| `-U`, `--no-update` | Disable update checking (default). |
| `-h`, `--help` | Display help information and exit. |
| `-v`, `--version` | Display version information and exit. |
If a configuration file is not explicitly provided, `sofmani` attempts to locate one automatically
in the current directory.

View File

@@ -139,8 +139,8 @@ func ContainsPlatform(platforms *[]Platform, platform Platform) bool {
return false
}
func ParseConfig() (*AppConfig, error) {
overrides := ParseCliConfig()
func ParseConfig(version string) (*AppConfig, error) {
overrides := ParseCliConfig(version)
file := overrides.ConfigFile
ext := filepath.Ext(file)
switch ext {
@@ -196,7 +196,7 @@ func tryConfigDir(dir string) string {
return ""
}
func ParseCliConfig() *AppCliConfig {
func ParseCliConfig(version string) *AppCliConfig {
args := os.Args[1:]
config := &AppCliConfig{}
file := FindConfigFile()
@@ -214,6 +214,18 @@ func ParseCliConfig() *AppCliConfig {
config.CheckUpdates = &fVal
case "-h", "--help":
fmt.Println("Usage: sofmani [options] [config_file]")
fmt.Println("Options:")
fmt.Println(" -d, --debug Enable debug mode")
fmt.Println(" -D, --no-debug Disable debug mode")
fmt.Println(" -u, --update Enable update checks")
fmt.Println(" -U, --no-update Disable update checks")
fmt.Println(" -h, --help Show this help message")
fmt.Println(" -v, --version Show version")
fmt.Println("")
fmt.Println("For online documentation, see https://github.com/chenasraf/sofmani/tree/master/docs")
os.Exit(0)
case "-v", "--version":
fmt.Println(version)
os.Exit(0)
default:
file = args[0]

View File

@@ -4,8 +4,8 @@ import (
"github.com/chenasraf/sofmani/appconfig"
)
func LoadConfig() (*appconfig.AppConfig, error) {
cfg, err := appconfig.ParseConfig()
func LoadConfig(version string) (*appconfig.AppConfig, error) {
cfg, err := appconfig.ParseConfig(version)
if err != nil {
return nil, err
}

View File

@@ -57,13 +57,14 @@ repository.
You can call `sofmani` with the following flags to alter the behavior for the current run:
| Flag | Description |
| ------------------- | ---------------------------------- |
| `-d`, `--debug` | Enable debug mode. |
| `-D`, `--no-debug` | Disable debug mode (default). |
| `-u`, `--update` | Enable update checking. |
| `-U`, `--no-update` | Disable update checking (default). |
| `-h`, `--help` | Display help information and exit. |
| Flag | Description |
| ------------------- | ------------------------------------- |
| `-d`, `--debug` | Enable debug mode. |
| `-D`, `--no-debug` | Disable debug mode (default). |
| `-u`, `--update` | Enable update checking. |
| `-U`, `--no-update` | Disable update checking (default). |
| `-h`, `--help` | Display help information and exit. |
| `-v`, `--version` | Display version information and exit. |
Each of these flags overrides the loaded config file, so while your default config can choose not to
check for updates by default, you or another user can add the `--update` flag to override this

View File

@@ -1,6 +1,7 @@
package main
import (
_ "embed"
"fmt"
"os"
@@ -8,8 +9,11 @@ import (
"github.com/chenasraf/sofmani/logger"
)
//go:embed version.txt
var version []byte
func main() {
cfg, err := LoadConfig()
cfg, err := LoadConfig(string(version))
if err != nil {
fmt.Println(fmt.Errorf("Error loading config: %v", err))
return