github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/swarm/swarm-snapshot/main.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:33</date>
    10  //</624450071928246272>
    11  
    12  
    13  package main
    14  
    15  import (
    16  	"os"
    17  
    18  	"github.com/ethereum/go-ethereum/cmd/utils"
    19  	"github.com/ethereum/go-ethereum/log"
    20  	cli "gopkg.in/urfave/cli.v1"
    21  )
    22  
    23  var gitCommit string //git sha1提交发布的哈希(通过链接器标志设置)
    24  
    25  //“创建”命令的默认值--节点标志
    26  const defaultNodes = 10
    27  
    28  func main() {
    29  	err := newApp().Run(os.Args)
    30  	if err != nil {
    31  		log.Error(err.Error())
    32  		os.Exit(1)
    33  	}
    34  }
    35  
    36  //newapp构建了一个新的swarm快照实用程序实例。
    37  //方法run在主函数和测试中对其进行调用。
    38  func newApp() (app *cli.App) {
    39  	app = utils.NewApp(gitCommit, "Swarm Snapshot Utility")
    40  
    41  	app.Name = "swarm-snapshot"
    42  	app.Usage = ""
    43  
    44  //应用程序标志(用于所有命令)
    45  	app.Flags = []cli.Flag{
    46  		cli.IntFlag{
    47  			Name:  "verbosity",
    48  			Value: 1,
    49  			Usage: "verbosity level",
    50  		},
    51  	}
    52  
    53  	app.Commands = []cli.Command{
    54  		{
    55  			Name:    "create",
    56  			Aliases: []string{"c"},
    57  			Usage:   "create a swarm snapshot",
    58  			Action:  create,
    59  //仅用于“创建”命令的标志。
    60  //允许在
    61  //命令参数。
    62  			Flags: append(app.Flags,
    63  				cli.IntFlag{
    64  					Name:  "nodes",
    65  					Value: defaultNodes,
    66  					Usage: "number of nodes",
    67  				},
    68  				cli.StringFlag{
    69  					Name:  "services",
    70  					Value: "bzz",
    71  					Usage: "comma separated list of services to boot the nodes with",
    72  				},
    73  			),
    74  		},
    75  	}
    76  
    77  	return app
    78  }
    79