Skip to content

Commit

Permalink
feat: add version info
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
  • Loading branch information
Abirdcfly committed Sep 5, 2022
1 parent c2ac5d0 commit c05eb39
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/dupword/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,26 @@
package main

import (
"fmt"
"runtime/debug"

"github.com/Abirdcfly/dupword"

"golang.org/x/tools/go/analysis/singlechecker"
)

func main() {
dupword.Version = buildVersion()
singlechecker.Main(dupword.NewAnalyzer())
}

var (
version = "dev"
commit = "none"
date = "now"
)

func buildVersion() string {
info, _ := debug.ReadBuildInfo()
return fmt.Sprintf("version\t%s\ncommit\t%s\ndate\t%s\n%s", version, commit, date, info.String())
}
1 change: 1 addition & 0 deletions dupword.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewAnalyzer() *analysis.Analyzer {
}
a.Flags.Init(Name, flag.ExitOnError)
a.Flags.Var(analyzer, "keyword", "key words for detecting duplicate words")
a.Flags.Var(version{}, "V", "print version and exit")
return a
}

Expand Down
41 changes: 41 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// MIT License
//
// # Copyright (c) 2022 Abirdcfly
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package dupword

import (
"fmt"
"os"
)

var Version = "dev"

type version struct{}

func (version) IsBoolFlag() bool { return true }
func (version) Get() interface{} { return nil }
func (version) String() string { return "" }
func (version) Set(_ string) error {
fmt.Println(Version)
os.Exit(0)
return nil
}

0 comments on commit c05eb39

Please sign in to comment.