Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miner: Remove unused win service cruft. #342

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 3 additions & 33 deletions cmd/miner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ var (
defaultUserAgent = fmt.Sprintf("%s/%s", "cpuminer", minerVersion())
)

// runServiceCommand is only set to a real function on Windows. It is used
// to parse and execute service commands specified via the -s flag.
var runServiceCommand func(string) error

// config describes the connection parameters for the client.
type config struct {
HomeDir string `long:"appdata" ini-name:"appdata" description:"Path to application home directory."`
Expand All @@ -60,12 +56,6 @@ type config struct {
net *chaincfg.Params
}

// serviceOptions defines the configuration options for the daemon as a service on
// Windows.
type serviceOptions struct {
ServiceCommand string `short:"s" long:"service" description:"Service command {install, remove, start, stop}"`
}

// validLogLevel returns whether or not logLevel is a valid debug log level.
func validLogLevel(logLevel string) bool {
_, ok := slog.LevelFromString(logLevel)
Expand Down Expand Up @@ -200,14 +190,8 @@ func cleanAndExpandPath(path string) string {
}

// newConfigParser returns a new command line flags parser.
func newConfigParser(cfg *config, so *serviceOptions, options flags.Options) (*flags.Parser, error) {
func newConfigParser(cfg *config, options flags.Options) (*flags.Parser, error) {
parser := flags.NewParser(cfg, options)
if runtime.GOOS == "windows" {
_, err := parser.AddGroup("Service Options", "Service Options", so)
if err != nil {
return nil, err
}
}
return parser, nil
}

Expand Down Expand Up @@ -236,15 +220,12 @@ func loadConfig() (*config, []string, error) {
Address: "",
}

// Service options which are only added on Windows.
serviceOpts := serviceOptions{}

// Pre-parse the command line options to see if an alternative config
// file or the version flag was specified. Any errors aside from the
// help message error can be ignored here since they will be caught by
// the final parse below.
preCfg := cfg
preParser, err := newConfigParser(&preCfg, &serviceOpts, flags.HelpFlag)
preParser, err := newConfigParser(&preCfg, flags.HelpFlag)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand All @@ -267,17 +248,6 @@ func loadConfig() (*config, []string, error) {
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
usageMessage := fmt.Sprintf("Use %s -h to show usage", appName)

// Perform service command and exit if specified. Invalid service
// commands show an appropriate error. Only runs on Windows since
// the runServiceCommand function will be nil when not on Windows.
if serviceOpts.ServiceCommand != "" && runServiceCommand != nil {
err := runServiceCommand(serviceOpts.ServiceCommand)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(0)
}

// Update the home directory for dcrpcclient if specified. Since the home
// directory is updated, other variables need to be updated to
// reflect the new changes.
Expand Down Expand Up @@ -320,7 +290,7 @@ func loadConfig() (*config, []string, error) {

// Load additional config from file.
var configFileError error
parser, err := newConfigParser(&cfg, &serviceOpts, flags.Default)
parser, err := newConfigParser(&cfg, flags.Default)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return nil, nil, err
Expand Down
Loading