Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#95): added freeze version flag #99

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 4 additions & 2 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ func helpPrinter(_ kong.HelpOptions, ctx *kong.Context) error {

fmt.Println()
for _, f := range flags {
if f.Name == "interactive" {
switch f.Name {
case "version", "interactive":
printFlag(f)
}
break
}
}

fmt.Println(titleStyle.Render("Settings"))
Expand Down
28 changes: 11 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,19 @@ 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)"
}
if config.Version {
if Version == "" {
Version = "latest (built from source)"
if info, ok := debug.ReadBuildInfo(); ok && (info.Main.Version != "" && info.Main.Version != "(devel)") {
Version = info.Main.Version
}
version := fmt.Sprintf("freeze version %s", Version)
if len(CommitSHA) >= shaLen {
version += " (" + CommitSHA[:shaLen] + ")"
}

fmt.Println(version)
os.Exit(0)
}
version := fmt.Sprintf("freeze version: %s", Version)
if len(CommitSHA) > shaLen { // if the commit SHA is longer than `shaLen` characters, show the first `shaLen` number of characters.
version += fmt.Sprintf(" (%s)", CommitSHA[:shaLen])
AlejandroSuero marked this conversation as resolved.
Show resolved Hide resolved
}
fmt.Println(version)
return
}

// Copy the pty output to buffer
Expand Down