mirror of
https://github.com/go-sigma/sigma.git
synced 2026-10-28 18:04:33 +08:00
Replace every `// <Identifier> ...` placeholder doc comment with a real description of the declared symbol. 276 comments in 71 files were rewritten: 149 top-level placeholders first, then a follow-up scan caught another 127 indented ones (interface methods and const blocks) that a column-anchored match had missed. Comments now open with the declared identifier and record the actual contract - behaviour, side effects, error/panic conditions, units, HTTP endpoints, lock keys and cache prefixes - instead of restating the signature. Three placeholders carried a stale identifier and were corrected to the declared symbol: ConfigurationDatabasePostgresql, GetImageRef and Initialize. No functional change: every modified line is a comment. Verification: - grep '^\s*//\s+\S+\s+\.\.\.\s*$' over all *.go returns no matches - gofmt -l over the changed files prints nothing - CGO_ENABLED=1 go build -tags "netgo,timetzdata,exclude_graphdriver_btrfs,containers_image_openpgp" ./... exits 0 - git diff HEAD -U0 filtered to non-comment changed lines is empty
106 lines
3.3 KiB
Go
106 lines
3.3 KiB
Go
// Copyright 2025 sigma
|
|
//
|
|
// 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 cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"runtime"
|
|
"strings"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/go-sigma/sigma/cmd/builder"
|
|
"github.com/go-sigma/sigma/cmd/distribution"
|
|
"github.com/go-sigma/sigma/cmd/server"
|
|
"github.com/go-sigma/sigma/cmd/tools"
|
|
"github.com/go-sigma/sigma/cmd/worker"
|
|
"github.com/go-sigma/sigma/pkg/config"
|
|
"github.com/go-sigma/sigma/pkg/logger"
|
|
"github.com/go-sigma/sigma/pkg/utils"
|
|
"github.com/go-sigma/sigma/pkg/version"
|
|
)
|
|
|
|
var cfgFile string
|
|
var logLevel string
|
|
|
|
// rootCmd represents the base command when called without any subcommands
|
|
func NewRootCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "sigma",
|
|
Short: "sigma is an OCI artifact storage and distribution system",
|
|
Long: `sigma is an OCI artifact storage and distribution system,
|
|
which is designed to be a lightweight, easy-to-use, and easy-to-deploy,
|
|
and can be used as a private registry or a public registry.
|
|
sigma is a cloud-native, distributed, and highly available system,
|
|
which can be deployed on any cloud platform or on-premises.`,
|
|
PersistentPreRun: func(_ *cobra.Command, _ []string) {
|
|
initConfig()
|
|
color.Cyan("Hello, sigma!")
|
|
fmt.Printf("Version: %s\n", version.Version)
|
|
fmt.Printf("GoVersion: %s\n", runtime.Version())
|
|
fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
|
fmt.Printf("BuildDate: %s\n", version.BuildDate)
|
|
fmt.Printf("GitCommit: %s\n", version.GitHash)
|
|
},
|
|
}
|
|
cmd.PersistentFlags().StringVarP(&cfgFile, "config", "c",
|
|
"/etc/sigma/config.yaml", "config file (default is /etc/sigma/config.yaml)")
|
|
cmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "info", "log level")
|
|
cmd.AddCommand(server.NewCmdServer())
|
|
cmd.AddCommand(worker.NewCmdWorker())
|
|
cmd.AddCommand(tools.NewCmdTools())
|
|
cmd.AddCommand(distribution.NewCmdDistribution())
|
|
cmd.AddCommand(builder.NewCmdBuilder())
|
|
return cmd
|
|
}
|
|
|
|
// Execute runs the root command and exits the process with status 1 if it
|
|
// returns an error.
|
|
func Execute() {
|
|
err := NewRootCmd().Execute()
|
|
if err != nil {
|
|
slog.Error("execute root command failed", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// initConfig reads in config file and ENV variables if set.
|
|
func initConfig() {
|
|
if strings.TrimSpace(cfgFile) == "" {
|
|
logger.Fatal("config file not found")
|
|
}
|
|
if !utils.IsExist(cfgFile) {
|
|
logger.Fatal("config file not exist", "config", cfgFile)
|
|
}
|
|
data, err := os.ReadFile(cfgFile)
|
|
if err != nil {
|
|
logger.Fatal("read config file failed", "err", err)
|
|
}
|
|
cfg := config.GetConfig()
|
|
err = yaml.Unmarshal(data, cfg)
|
|
if err != nil {
|
|
logger.Fatal("unmarshal failed", "err", err)
|
|
}
|
|
err = cfg.ApplyEnvOverrides()
|
|
if err != nil {
|
|
logger.Fatal("apply env config overrides failed", "err", err)
|
|
}
|
|
logger.SetLevel(cfg.Log.Level.String())
|
|
}
|