mirror of
https://github.com/chenasraf/sofmani.git
synced 2026-05-17 17:28:04 +00:00
fix: show version number
This commit is contained in:
15
README.md
15
README.md
@@ -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.
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
6
main.go
6
main.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user