1+ // Package command provides the core command execution infrastructure for gitlab-shell.
2+ // It defines the Command interface that all shell commands must implement,
3+ // along with shared utilities for logging, tracing, and context management.
14package command
25
36import (
@@ -12,17 +15,21 @@ import (
1215 "gitlab.com/gitlab-org/labkit/tracing"
1316)
1417
18+ // Command is the interface that all gitlab-shell commands must implement.
19+ // Execute runs the command and returns the updated context and any error.
1520type Command interface {
1621 Execute (ctx context.Context ) (context.Context , error )
1722}
1823
24+ // LogMetadata contains project and namespace information for structured logging.
1925type LogMetadata struct {
2026 Project string `json:"project,omitempty"`
2127 RootNamespace string `json:"root_namespace,omitempty"`
2228 ProjectID int `json:"project_id,omitempty"`
2329 RootNamespaceID int `json:"root_namespace_id,omitempty"`
2430}
2531
32+ // LogData contains user and request information for structured logging.
2633type LogData struct {
2734 Username string `json:"username"`
2835 WrittenBytes int64 `json:"written_bytes"`
@@ -34,6 +41,8 @@ type contextKey string
3441// LogDataKey is the context key used to store log data in request contexts.
3542const LogDataKey contextKey = "logData"
3643
44+ // CheckForVersionFlag checks if the -version flag was passed and prints version info if so.
45+ // It exits the program after printing the version.
3746func CheckForVersionFlag (osArgs []string , version , buildTime string ) {
3847 // We can't use the flag library because gitlab-shell receives other arguments
3948 // that confuse the parser.
@@ -45,7 +54,7 @@ func CheckForVersionFlag(osArgs []string, version, buildTime string) {
4554 }
4655}
4756
48- // Setup() initializes tracing from the configuration file and generates a
57+ // Setup initializes tracing from the configuration file and generates a
4958// background context from which all other contexts in the process should derive
5059// from, as it has a service name and initial correlation ID set.
5160func Setup (serviceName string , config * config.Config ) (context.Context , func ()) {
@@ -77,10 +86,12 @@ func Setup(serviceName string, config *config.Config) (context.Context, func())
7786
7887 return ctx , func () {
7988 finished ()
80- closer .Close ()
89+ _ = closer .Close ()
8190 }
8291}
8392
93+ // NewLogData creates a new LogData instance with the given project, username, and IDs.
94+ // It extracts the root namespace from the project path.
8495func NewLogData (project , username string , projectID , rootNamespaceID int ) LogData {
8596 rootNameSpace := ""
8697
0 commit comments