github.com/decred/politeia@v1.4.0/politeiad/cmd/legacypoliteia/legacypoliteia.go (about)

     1  // Copyright (c) 2022 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"flag"
     9  	"fmt"
    10  	"os"
    11  )
    12  
    13  const (
    14  	// Command names. See the usage.go file for details on command usage.
    15  	convertCmdName = "convert"
    16  	importCmdName  = "import"
    17  
    18  	// filePermissions is the file permissions that are used for all directory
    19  	// and file creation in this tool.
    20  	filePermissions = 0755
    21  )
    22  
    23  func _main() error {
    24  	// Parse the CLI args
    25  	flag.Parse()
    26  	args := flag.Args()
    27  	if len(args) == 0 {
    28  		fmt.Fprintln(os.Stderr, usageMsg)
    29  		return fmt.Errorf("no command specified")
    30  	}
    31  
    32  	// Execute the specified command
    33  	switch args[0] {
    34  	case convertCmdName:
    35  		return execConvertCmd(args[1:])
    36  	case importCmdName:
    37  		return execImportCmd(args[1:])
    38  	default:
    39  		return fmt.Errorf("command '%v' not found", args[0])
    40  	}
    41  }
    42  
    43  func main() {
    44  	// Use a custom help message
    45  	flag.Usage = func() {
    46  		fmt.Fprintln(os.Stderr, usageMsg)
    47  	}
    48  	err := _main()
    49  	if err != nil {
    50  		fmt.Fprintf(os.Stderr, "%v\n", err)
    51  		os.Exit(1)
    52  	}
    53  }