mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:51:59 +00:00
svcmain: introduce urfave/cli (#49518)
This is a minimal usage. The only thing we get in this commit is the possibility to extend this in the future. Additionally we get output when you run --help. Test Plan: .bin/sourcegraph --help and sg start app continue to work
This commit is contained in:
parent
e1f8f7adbf
commit
eae45a8efd
@ -2,6 +2,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
blobstore_shared "github.com/sourcegraph/sourcegraph/cmd/blobstore/shared"
|
||||
frontend_shared "github.com/sourcegraph/sourcegraph/cmd/frontend/shared"
|
||||
githubproxy_shared "github.com/sourcegraph/sourcegraph/cmd/github-proxy/shared"
|
||||
@ -29,5 +31,5 @@ var services = []service.Service{
|
||||
}
|
||||
|
||||
func main() {
|
||||
osscmd.MainOSS(services)
|
||||
osscmd.MainOSS(services, os.Args)
|
||||
}
|
||||
|
||||
@ -17,8 +17,8 @@ var config = svcmain.Config{
|
||||
}
|
||||
|
||||
// Main is called from the `main` function of the `sourcegraph-oss` command.
|
||||
func MainOSS(services []service.Service) {
|
||||
svcmain.Main(services, config)
|
||||
func MainOSS(services []service.Service, args []string) {
|
||||
svcmain.Main(services, config, args)
|
||||
}
|
||||
|
||||
// DeprecatedSingleServiceMainOSS is called from the `main` function of a command in the OSS build
|
||||
|
||||
@ -12,8 +12,8 @@ import (
|
||||
var config = svcmain.Config{}
|
||||
|
||||
// MainEnterprise is called from the `main` function of the `sourcegraph` command.
|
||||
func MainEnterprise(services []service.Service) {
|
||||
svcmain.Main(services, config)
|
||||
func MainEnterprise(services []service.Service, args []string) {
|
||||
svcmain.Main(services, config, args)
|
||||
}
|
||||
|
||||
// DeprecatedSingleServiceMainEnterprise is called from the `main` function of a command in the
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/sourcegraph/enterprisecmd"
|
||||
"github.com/sourcegraph/sourcegraph/internal/service"
|
||||
"github.com/sourcegraph/sourcegraph/internal/service/servegit"
|
||||
@ -33,5 +35,5 @@ var services = []service.Service{
|
||||
}
|
||||
|
||||
func main() {
|
||||
enterprisecmd.MainEnterprise(services)
|
||||
enterprisecmd.MainEnterprise(services, os.Args)
|
||||
}
|
||||
|
||||
@ -3,12 +3,15 @@ package svcmain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/sourcegraph/log"
|
||||
"github.com/sourcegraph/log/output"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
|
||||
@ -29,8 +32,11 @@ type Config struct {
|
||||
AfterConfigure func() // run after all services' Configure hooks are called
|
||||
}
|
||||
|
||||
// Main is called from the `main` function of the `sourcegraph-oss` and `sourcegraph` commands.
|
||||
func Main(services []sgservice.Service, config Config) {
|
||||
// Main is called from the `main` function of the `sourcegraph-oss` and
|
||||
// `sourcegraph` commands.
|
||||
//
|
||||
// args is the commandline arguments (usually os.Args).
|
||||
func Main(services []sgservice.Service, config Config, args []string) {
|
||||
// Unlike other sourcegraph binaries we expect Sourcegraph App to be run
|
||||
// by a user instead of deployed to a cloud. So adjust the default output
|
||||
// format before initializing log.
|
||||
@ -50,9 +56,28 @@ func Main(services []sgservice.Service, config Config) {
|
||||
},
|
||||
),
|
||||
)
|
||||
logger := log.Scoped("sourcegraph", "Sourcegraph")
|
||||
singleprogram.Init(logger)
|
||||
run(liblog, logger, services, config, true, true)
|
||||
|
||||
runCommand := &cli.Command{
|
||||
Name: "run",
|
||||
Usage: "Run the Sourcegraph App",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
logger := log.Scoped("sourcegraph", "Sourcegraph")
|
||||
singleprogram.Init(logger)
|
||||
run(liblog, logger, services, config, true, true)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = filepath.Base(args[0])
|
||||
app.Usage = "The Sourcegraph App"
|
||||
app.Version = version.Version()
|
||||
app.Action = runCommand.Action
|
||||
|
||||
if err := app.Run(args); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// DeprecatedSingleServiceMain is called from the `main` function of a command to start a single
|
||||
|
||||
Loading…
Reference in New Issue
Block a user