Skip to content

Commit

Permalink
feat(charmbracelet#95): added freeze version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed May 31, 2024
1 parent fc03c0d commit 67a75c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {

// Settings
Config string `json:"config,omitempty" help:"Base configuration file or template." short:"c" group:"Settings" default:"default" placeholder:"base"`
Version bool `hidden:"" json:",omitempty" help:"Show version and exit." short:"v" group:"Settings"`
Interactive bool `hidden:"" json:",omitempty" help:"Use an interactive form for configuration options." short:"i" group:"Settings"`
Language string `json:"language,omitempty" help:"Language of code file." short:"l" group:"Settings" placeholder:"go"`
Theme string `json:"theme" help:"Theme to use for syntax highlighting." short:"t" group:"Settings" placeholder:"charm"`
Expand Down
2 changes: 1 addition & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func helpPrinter(_ kong.HelpOptions, ctx *kong.Context) error {

fmt.Println()
for _, f := range flags {
if f.Name == "interactive" {
if f.Name == "version" || f.Name == "interactive" {
printFlag(f)
}
}
Expand Down
29 changes: 12 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,20 @@ func main() {
printErrorFatal("Invalid Usage", err)
}

if len(ctx.Args) > 0 {
switch ctx.Args[0] {

case "version":
if Version == "" {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
Version = info.Main.Version
} else {
Version = "unknown (built from source)"
}
}
version := fmt.Sprintf("freeze version %s", Version)
if len(CommitSHA) >= shaLen {
version += " (" + CommitSHA[:shaLen] + ")"
if config.Version {
if Version == "" {
if info, ok := debug.ReadBuildInfo(); ok && (info.Main.Version != "" && info.Main.Version != "(devel)") {
Version = info.Main.Version
} else {
Version = "latest (built from source)"
}

fmt.Println(version)
os.Exit(0)
}
version := fmt.Sprintf("freeze version: %s", Version)
if len(CommitSHA) > 7 {
version += fmt.Sprintf(" (%s)", CommitSHA[:shaLen])
}
fmt.Println(version)
os.Exit(0)
}

// Copy the pty output to buffer
Expand Down

0 comments on commit 67a75c9

Please sign in to comment.