github.com/iotexproject/iotex-core@v1.14.1-rc1/tools/ioctl/readme/docgen.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	"github.com/spf13/cobra"
     9  
    10  	"github.com/iotexproject/iotex-core/ioctl/cmd"
    11  	"github.com/iotexproject/iotex-core/ioctl/doc"
    12  )
    13  
    14  var ioctlPath string
    15  
    16  func main() {
    17  	toolName := "ioctl"
    18  	corePath, err := filepath.Abs(".")
    19  	if err != nil {
    20  		log.Fatal(err)
    21  	}
    22  	ioctlPath = filepath.Join(corePath, "tools", toolName)
    23  
    24  	preString := `# ioctl
    25  ioctl is a command-line interface for interacting with IoTeX blockchains.
    26  
    27  # Build
    28  ` + "`./buildcli.sh`\n" + `
    29  
    30  If you want to build ioctl on Windows, you need to install mingw. Package manager [Chocolatey](https://chocolatey.org/) provides an easy way to intall latest mingw.
    31  ` + "`C:\\Windows\\system32> choco install mingw`\n" + `
    32  
    33  After this command, target bin files will be placed in ./release/ folder, upload them to
    34  specific release so install-cli.sh can download them.
    35  
    36  # Install
    37  ## Install released build
    38      curl --silent https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-cli.sh | sh
    39  
    40  ## Install latest build
    41      curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-cli.sh | sh -s "unstable"
    42  `
    43  	rootCmd := cmd.NewIoctl()
    44  
    45  	linkHandler := func(c *cobra.Command, s string) string {
    46  		if c == rootCmd {
    47  			return "readme/" + s
    48  		}
    49  		if strings.Contains(s, "ioctl.md") {
    50  			return "../README.md"
    51  		}
    52  		return s
    53  	}
    54  
    55  	filePrepender := func(s string) string {
    56  		if strings.Contains(s, "README.md") {
    57  			return preString
    58  		}
    59  		return ""
    60  	}
    61  
    62  	path := filepath.Join(ioctlPath, "readme")
    63  	err = doc.GenMarkdownTreeCustom(rootCmd, path, toolName, ioctlPath, filePrepender, linkHandler)
    64  	if err != nil {
    65  		log.Fatal(err)
    66  	}
    67  }