Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1100 from Starnop/supernode-cli-docs
Browse files Browse the repository at this point in the history
[feature]: add generate doc cmd for supernode
  • Loading branch information
yeya24 committed Nov 28, 2019
2 parents 72b98ba + c7ae59b commit f8ecf02
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 72 deletions.
66 changes: 0 additions & 66 deletions cmd/dfdaemon/app/gen_doc.go

This file was deleted.

2 changes: 2 additions & 0 deletions cmd/dfdaemon/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/dragonflyoss/Dragonfly/dfdaemon"
"github.com/dragonflyoss/Dragonfly/dfdaemon/config"
"github.com/dragonflyoss/Dragonfly/dfdaemon/constant"
"github.com/dragonflyoss/Dragonfly/pkg/cmd"
dferr "github.com/dragonflyoss/Dragonfly/pkg/errortypes"
"github.com/dragonflyoss/Dragonfly/pkg/netutils"
"github.com/dragonflyoss/Dragonfly/pkg/rate"
Expand Down Expand Up @@ -105,6 +106,7 @@ func init() {
rf.StringSlice("node", nil, "specify the addresses(host:port) of supernodes that will be passed to dfget.")

exitOnError(bindRootFlags(viper.GetViper()), "bind root command flags")
rootCmd.AddCommand(cmd.NewGenDocCommand("dfdaemon"))
}

// bindRootFlags binds flags on rootCmd to the given viper instance.
Expand Down
2 changes: 2 additions & 0 deletions cmd/dfget/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/dragonflyoss/Dragonfly/dfget/config"
"github.com/dragonflyoss/Dragonfly/dfget/core"
"github.com/dragonflyoss/Dragonfly/pkg/cmd"
"github.com/dragonflyoss/Dragonfly/pkg/dflog"
"github.com/dragonflyoss/Dragonfly/pkg/errortypes"
"github.com/dragonflyoss/Dragonfly/pkg/printer"
Expand Down Expand Up @@ -67,6 +68,7 @@ var rootCmd = &cobra.Command{

func init() {
initFlags()
rootCmd.AddCommand(cmd.NewGenDocCommand("dfget"))
}

// runDfget does some init operations and starts to download.
Expand Down
12 changes: 10 additions & 2 deletions cmd/supernode/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"reflect"
"time"

"github.com/dragonflyoss/Dragonfly/pkg/cmd"
"github.com/dragonflyoss/Dragonfly/pkg/dflog"
"github.com/dragonflyoss/Dragonfly/pkg/errortypes"
"github.com/dragonflyoss/Dragonfly/pkg/fileutils"
Expand Down Expand Up @@ -50,9 +51,15 @@ var (
supernodeViper = viper.GetViper()
)

// supernodeDescription is used to describe supernode command in details.
var supernodeDescription = `SuperNode is a long-running process with two primary responsibilities:
It's the tracker and scheduler in the P2P network that choose appropriate downloading net-path for each peer.
It's also a CDN server that caches downloaded data from source to avoid downloading the same files from source repeatedly.`

var rootCmd = &cobra.Command{
Use: "Dragonfly Supernode",
Long: "",
Use: "supernode",
Short: "the central control server of Dragonfly used for scheduling and cdn cache",
Long: supernodeDescription,
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -115,6 +122,7 @@ var rootCmd = &cobra.Command{

func init() {
setupFlags(rootCmd)
rootCmd.AddCommand(cmd.NewGenDocCommand("supernode"))
}

// setupFlags setups flags for command line.
Expand Down
2 changes: 2 additions & 0 deletions hack/generate-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ generate-cli-docs(){
CLI_DOCS_DIR=$(cd "../docs/cli_reference" && pwd)
DFGET_BIN_PATH=../"${BUILD_PATH}"/dfget
DFDAEMON_BIN_PATH=../"${BUILD_PATH}"/dfdaemon
SUPERNODE_BIN_PATH=../"${BUILD_PATH}"/supernode

${DFGET_BIN_PATH} gen-doc -p "${CLI_DOCS_DIR}" || return
${DFDAEMON_BIN_PATH} gen-doc -p "${CLI_DOCS_DIR}" || return
${SUPERNODE_BIN_PATH} gen-doc -p "${CLI_DOCS_DIR}" || return
echo "Generate: CLI docs in ${CLI_DOCS_DIR}"
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/dfget/app/gen_doc.go → pkg/cmd/gen_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package app
package cmd

import (
"fmt"
Expand All @@ -32,11 +32,11 @@ type GenDocCommand struct {
path string
}

func init() {
func NewGenDocCommand(name string) *cobra.Command {
genDocCommand := &GenDocCommand{}
genDocCommand.cmd = &cobra.Command{
Use: "gen-doc",
Short: "Generate Document for dfget command line tool with MarkDown format",
Short: fmt.Sprintf("Generate Document for %s command line tool in MarkDown format", name),
Args: cobra.NoArgs,
SilenceErrors: true,
SilenceUsage: true,
Expand All @@ -45,7 +45,7 @@ func init() {
},
}
genDocCommand.addFlags()
rootCmd.AddCommand(genDocCommand.cmd)
return genDocCommand.cmd
}

// addFlags adds flags for specific command.
Expand Down

0 comments on commit f8ecf02

Please sign in to comment.