As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit a6072938 authored by Ash McKenzie's avatar Ash McKenzie
Browse files

Move version flag check into command package

parent 5da77e27
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"path"
checkCmd "gitlab.com/gitlab-org/gitlab-shell/v14/cmd/check/command"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command"
Loading
Loading
@@ -21,12 +20,7 @@ var (
)
func main() {
// We can't use the flag library because gitlab-shell receives other arguments
// that confuse the parser.
if len(os.Args) == 2 && os.Args[1] == "-version" {
fmt.Printf("%s %s-%s\n", path.Base(os.Args[0]), Version, BuildTime)
os.Exit(0)
}
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
Loading
Loading
Loading
Loading
@@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"path"
cmd "gitlab.com/gitlab-org/gitlab-shell/v14/cmd/gitlab-shell-authorized-keys-check/command"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command"
Loading
Loading
@@ -22,12 +21,7 @@ var (
)
func main() {
// We can't use the flag library because gitlab-shell receives other arguments
// that confuse the parser.
if len(os.Args) == 2 && os.Args[1] == "-version" {
fmt.Printf("%s %s-%s\n", path.Base(os.Args[0]), Version, BuildTime)
os.Exit(0)
}
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
Loading
Loading
Loading
Loading
@@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"path"
cmd "gitlab.com/gitlab-org/gitlab-shell/v14/cmd/gitlab-shell-authorized-principals-check/command"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command"
Loading
Loading
@@ -22,12 +21,7 @@ var (
)
func main() {
// We can't use the flag library because gitlab-shell receives other arguments
// that confuse the parser.
if len(os.Args) == 2 && os.Args[1] == "-version" {
fmt.Printf("%s %s-%s\n", path.Base(os.Args[0]), Version, BuildTime)
os.Exit(0)
}
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
Loading
Loading
Loading
Loading
@@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"path"
"reflect"
grpccodes "google.golang.org/grpc/codes"
Loading
Loading
@@ -30,12 +29,7 @@ var (
)
func main() {
// We can't use the flag library because gitlab-shell receives other arguments
// that confuse the parser.
if len(os.Args) == 2 && os.Args[1] == "-version" {
fmt.Printf("%s %s-%s\n", path.Base(os.Args[0]), Version, BuildTime)
os.Exit(0)
}
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
Loading
Loading
Loading
Loading
@@ -3,7 +3,6 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
Loading
Loading
@@ -20,7 +19,6 @@ import (
var (
configDir = flag.String("config-dir", "", "The directory the config is in")
version = flag.Bool("version", false, "Prints current version")
// Version is the current version of gitlab-shell
Version = "(unknown version)" // Set at build time in the Makefile
Loading
Loading
@@ -41,16 +39,12 @@ func overrideConfigFromEnvironment(cfg *config.Config) {
if gitlabLogFormat := os.Getenv("GITLAB_LOG_FORMAT"); gitlabLogFormat != "" {
cfg.LogFormat = gitlabLogFormat
}
return
}
func main() {
flag.Parse()
command.CheckForVersionFlag(os.Args, Version, BuildTime)
if *version {
fmt.Printf("gitlab-sshd %s-%s\n", Version, BuildTime)
os.Exit(0)
}
flag.Parse()
cfg := new(config.Config)
if *configDir != "" {
Loading
Loading
Loading
Loading
@@ -2,6 +2,9 @@ package command
import (
"context"
"fmt"
"os"
"path"
"strings"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
Loading
Loading
@@ -19,6 +22,17 @@ type LogMetadata struct {
RootNamespace string `json:"root_namespace,omitempty"`
}
func CheckForVersionFlag(osArgs []string, version, buildTime string) {
// We can't use the flag library because gitlab-shell receives other arguments
// that confuse the parser.
//
// See: https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/800#note_1459474735
if len(osArgs) == 2 && osArgs[1] == "-version" {
fmt.Printf("%s %s-%s\n", path.Base(osArgs[0]), version, buildTime)
os.Exit(0)
}
}
// Setup() initializes tracing from the configuration file and generates a
// background context from which all other contexts in the process should derive
// from, as it has a service name and initial correlation ID set.
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@ package command
import (
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/require"
Loading
Loading
@@ -74,7 +75,6 @@ func addAdditionalEnv(envMap map[string]string) func() {
for _, k := range unsetValues {
os.Unsetenv(k)
}
}
}
Loading
Loading
@@ -114,3 +114,17 @@ func TestNewLogMetadata(t *testing.T) {
})
}
}
func TestCheckForVersionFlag(t *testing.T) {
if os.Getenv("GITLAB_SHELL_TEST_CHECK_FOR_VERSION_FLAG") == "1" {
CheckForVersionFlag([]string{"test", "-version"}, "1.2.3", "456")
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestCheckForVersionFlag")
cmd.Env = append(os.Environ(), "GITLAB_SHELL_TEST_CHECK_FOR_VERSION_FLAG=1")
out, err := cmd.Output()
require.Nil(t, err)
require.Equal(t, "test 1.2.3-456\n", string(out))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment