Welcome to mirror list, hosted at ThFree Co, Russian Federation.

featureflags.go « gitaly-git2go « cmd - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 055f18be91aa673e4e6e0bf019e3a87499289736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//go:build static && system_libgit2 && gitaly_test

package main

import (
	"context"
	"encoding/gob"
	"flag"

	"gitlab.com/gitlab-org/gitaly/v16/internal/featureflag"
	"gitlab.com/gitlab-org/gitaly/v16/internal/git2go"
)

// This subcommand is only called in tests, so we don't want to register it like
// the other subcommands but instead will do it in an init block. The gitaly_test build
// flag will guarantee that this is not built and registered in the
// gitaly-git2go binary
func init() {
	subcommands["feature-flags"] = &featureFlagsSubcommand{}
}

type featureFlagsSubcommand struct{}

func (featureFlagsSubcommand) Flags() *flag.FlagSet {
	return flag.NewFlagSet("feature-flags", flag.ExitOnError)
}

func (featureFlagsSubcommand) Run(ctx context.Context, decoder *gob.Decoder, encoder *gob.Encoder) error {
	var flags []git2go.FeatureFlag
	for flag, value := range featureflag.FromContext(ctx) {
		flags = append(flags, git2go.FeatureFlag{
			Name:        flag.Name,
			MetadataKey: flag.MetadataKey(),
			Value:       value,
		})
	}

	return encoder.Encode(git2go.FeatureFlags{
		Flags: flags,
	})
}