Skip to content

Commit

Permalink
Feat: add loggie version sub command (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethfoo committed Mar 24, 2023
1 parent 1522f8c commit a0877f4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/subcmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package subcmd
import (
"github.com/loggie-io/loggie/cmd/subcmd/genfiles"
"github.com/loggie-io/loggie/cmd/subcmd/inspect"
"github.com/loggie-io/loggie/cmd/subcmd/version"
"os"
)

Expand All @@ -36,6 +37,11 @@ func SwitchSubCommand() error {
if err := genfiles.RunGenFiles(); err != nil {
return err
}

case version.SubCommandVersion:
if err := version.RunVersion(); err != nil {
return err
}
}

return nil
Expand Down
48 changes: 48 additions & 0 deletions cmd/subcmd/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2023 Loggie Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"errors"
"flag"
"fmt"
"github.com/loggie-io/loggie/pkg/core/global"
"os"
)

const (
SubCommandVersion = "version"
)

var (
versionCmd *flag.FlagSet
)

func init() {
versionCmd = flag.NewFlagSet(SubCommandVersion, flag.ExitOnError)
}

func RunVersion() error {
if len(os.Args) > 2 {
if err := versionCmd.Parse(os.Args[2:]); err != nil {
return err
}
}

fmt.Printf("Loggie version: %s\n", global.GetVersion())
return errors.New("exit")
}

0 comments on commit a0877f4

Please sign in to comment.