Skip to content

Commit

Permalink
Doc.0 (#15)
Browse files Browse the repository at this point in the history
* doc command added

* add long description for commands

* minor text changes

* minor text changes
  • Loading branch information
asabya authored Sep 15, 2021
1 parent e33fd69 commit 81b7146
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 76 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from [ipfs-lite](https://github.com/hsanjuan/ipfs-lite).
It offers all the features of main [ipfs-lite](https://github.com/hsanjuan/ipfs-lite). For certain requirements of
datahop it adds some more features of full ipfs, such as config, repo, leveldb etc.

## Running Example
## Examples

### cli client
```
Expand All @@ -31,10 +31,10 @@ datahop it adds some more features of full ipfs, such as config, repo, leveldb e
* [x] generate gomobile binding for android
* [x] adding content
* [x] replicating content
* [ ] remove content
* [ ] remove respective replication info for removed content
* [x] remove content
* [x] remove respective replication info for removed content
* [x] bootstrap mobile client
* [ ] cli for bootstrap peer
* [x] cli for bootstrap peer


## Documentation
Expand Down
19 changes: 14 additions & 5 deletions cli/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ import (
)

func InitAddCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
addCommand := &cobra.Command{
Use: "add",
Short: "Add content into datahop network",
Long: `Add Long Description`,
Args: cobra.MinimumNArgs(1),
Long: `
This command is used to add a file/content in the
datahop network addressable by a given tag.
`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if comm.LitePeer == nil || !comm.LitePeer.IsOnline() {
return errors.New("daemon not running")
}
filePath := args[0]
log.Debug(filePath)
fileinfo, err := os.Lstat(filePath)
if err != nil {
log.Errorf("Failed executing share command Err:%s", err.Error())
Expand Down Expand Up @@ -57,12 +59,19 @@ func InitAddCmd(comm *common.Common) *cobra.Command {
Timestamp: time.Now().Unix(),
Owner: comm.LitePeer.Host.ID(),
}
err = comm.LitePeer.Manager.Tag(f.Name(), meta)
tag, _ := cmd.Flags().GetString("tag")
if tag == "" {
tag = f.Name()
}
err = comm.LitePeer.Manager.Tag(tag, meta)
if err != nil {
return err
}
cmd.Printf("%s added with cid : %s", filePath, n.Cid().String())
return nil
},
}
addCommand.Flags().StringP("tag", "t", "",
"Tag for the file/content")
return addCommand
}
22 changes: 18 additions & 4 deletions cli/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ func InitDaemonCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "daemon",
Short: "Start datahop daemon",
Long: `Add Long Description`,
PreRun: func(cmd *cobra.Command, args []string) {

},
Long: `
This command is used to start the Datahop Daemon.
`,
Run: func(cmd *cobra.Command, args []string) {
litePeer, err := ipfslite.New(comm.Context, comm.Cancel, comm.Repo)
if err != nil {
Expand All @@ -56,6 +55,21 @@ func InitDaemonCmd(comm *common.Common) *cobra.Command {
log.Error(err)
os.Exit(1)
}
datahopCli := `
__ __ __ __ __
/ | / | / | / |/ |
____$$ | ______ _$$ |_ ______ $$ |____ ______ ______ _______ $$ |$$/
/ $$ | / \ / $$ | / \ $$ \ / \ / \ ______ / |$$ |/ |
/$$$$$$$ | $$$$$$ |$$$$$$/ $$$$$$ |$$$$$$$ |/$$$$$$ |/$$$$$$ |/ |/$$$$$$$/ $$ |$$ |
$$ | $$ | / $$ | $$ | __ / $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$$$$$/ $$ | $$ |$$ |
$$ \__$$ |/$$$$$$$ | $$ |/ |/$$$$$$$ |$$ | $$ |$$ \__$$ |$$ |__$$ | $$ \_____ $$ |$$ |
$$ $$ |$$ $$ | $$ $$/ $$ $$ |$$ | $$ |$$ $$/ $$ $$/ $$ |$$ |$$ |
$$$$$$$/ $$$$$$$/ $$$$/ $$$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/
$$ |
$$ |
$$/
`
fmt.Println(datahopCli)
fmt.Println("Datahop daemon running on port", cfg.SwarmPort)
var sigChan chan os.Signal
sigChan = make(chan os.Signal, 1)
Expand Down
36 changes: 36 additions & 0 deletions cli/cmd/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"fmt"

"github.com/datahop/ipfs-lite/cli/common"
"github.com/datahop/ipfs-lite/cli/out"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

func InitializeDocCommand(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "doc",
Short: "Use to generate documentation",
Long: `
This command is used to generate documentation
for the CLI.
`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
dir := args[0]
var err error
err = doc.GenMarkdownTree(cmd.Root(), dir)
if err != nil {
return err
}
err = out.Print(cmd, fmt.Sprintf("Documentation generated at %s", dir), parseFormat(cmd))
if err != nil {
log.Error("Unable to get config ", err)
return err
}
return nil
},
}
}
11 changes: 9 additions & 2 deletions cli/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ func InitGetCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "get",
Short: "Get content by tag",
Long: `Add Long Description`,
Args: cobra.MinimumNArgs(1),
Long: `
"The commend is used to get file/content from the
datahop network by a simple tag"
`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// TODO get command
// Git command will have an --l or -location flag to save
// the file at a specific location , else it will stream
// the content into stdout
cmd.Printf("Get Placeholder")
},
}
Expand Down
19 changes: 4 additions & 15 deletions cli/cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ func InitIndexCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "index",
Short: "Index datahop node content",
Long: `Add Long Description`,
Long: `
"The commend is used to get the index of tag-content"
`,
RunE: func(cmd *cobra.Command, args []string) error {
if comm.LitePeer == nil || !comm.LitePeer.IsOnline() {
return errors.New("daemon not running")
Expand All @@ -23,20 +25,7 @@ func InitIndexCmd(comm *common.Common) *cobra.Command {
}

// output
pFlag, _ := cmd.Flags().GetBool("pretty")
jFlag, _ := cmd.Flags().GetBool("json")
log.Debug(pFlag, jFlag)
var f out.Format
if jFlag {
f = out.Json
}
if pFlag {
f = out.PrettyJson
}
if !pFlag && !jFlag {
f = out.NoStyle
}
err = out.Print(cmd, tags, f)
err = out.Print(cmd, tags, parseFormat(cmd))
if err != nil {
log.Error("Unable to get config ", err)
return err
Expand Down
46 changes: 22 additions & 24 deletions cli/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ func InitInfoCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "info",
Short: "Get datahop node information",
Long: `Add Long Description`,
Long: `
"The commend is used to get the local node information"
`,
RunE: func(cmd *cobra.Command, args []string) error {
info := &Info{}

if comm.LitePeer != nil {
// is daemon running
info.IsDaemonRunning = comm.LitePeer.IsOnline()

// peers
info.Peers = comm.LitePeer.Peers()

// addresses
addrs := []string{}
if comm.LitePeer != nil {
Expand All @@ -45,7 +44,6 @@ func InitInfoCmd(comm *common.Common) *cobra.Command {
}
info.Addresses = addrs
}

// disk usage
du, err := datastore.DiskUsage(comm.LitePeer.Repo.Datastore())
if err != nil {
Expand All @@ -56,11 +54,7 @@ func InitInfoCmd(comm *common.Common) *cobra.Command {
} else {
info.IsDaemonRunning = false
}
// config
// id
// address
// public key
// port

cfg, err := comm.Repo.Config()
if err != nil {
log.Error("Unable to get config ", err)
Expand All @@ -73,20 +67,7 @@ func InitInfoCmd(comm *common.Common) *cobra.Command {
info.CRDTStatus = comm.Repo.State()

// output
pFlag, _ := cmd.Flags().GetBool("pretty")
jFlag, _ := cmd.Flags().GetBool("json")
log.Debug(pFlag, jFlag)
var f out.Format
if jFlag {
f = out.Json
}
if pFlag {
f = out.PrettyJson
}
if !pFlag && !jFlag {
f = out.NoStyle
}
err = out.Print(cmd, info, f)
err = out.Print(cmd, info, parseFormat(cmd))
if err != nil {
log.Error("Unable to get config ", err)
return err
Expand All @@ -95,3 +76,20 @@ func InitInfoCmd(comm *common.Common) *cobra.Command {
},
}
}

func parseFormat(cmd *cobra.Command) out.Format {
pFlag, _ := cmd.Flags().GetBool("pretty")
jFlag, _ := cmd.Flags().GetBool("json")
log.Debug(pFlag, jFlag)
var f out.Format
if jFlag {
f = out.Json
}
if pFlag {
f = out.PrettyJson
}
if !pFlag && !jFlag {
f = out.NoStyle
}
return f
}
22 changes: 6 additions & 16 deletions cli/cmd/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,22 @@ import (
func InitMatrixCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "matrix",
Short: "Get node connectivity and content matirx",
Long: `Add Long Description`,
Short: "Get node connectivity and content matrix",
Long: `
"The commend is used to get connectivity and
content matrix"
`,
RunE: func(cmd *cobra.Command, args []string) error {
if comm.LitePeer != nil {
nodeMatrixSnapshot := comm.LitePeer.Repo.Matrix().NodeMatrixSnapshot()
contentMatrixSnapshot := comm.LitePeer.Repo.Matrix().ContentMatrixSnapshot()
uptime := comm.LitePeer.Repo.Matrix().GetTotalUptime()
// output
pFlag, _ := cmd.Flags().GetBool("pretty")
jFlag, _ := cmd.Flags().GetBool("json")
log.Debug(pFlag, jFlag)
var f out.Format
if jFlag {
f = out.Json
}
if pFlag {
f = out.PrettyJson
}
if !pFlag && !jFlag {
f = out.NoStyle
}
matrix := map[string]interface{}{}
matrix["TotalUptime"] = uptime
matrix["NodeMatrix"] = nodeMatrixSnapshot
matrix["ContentMatrix"] = contentMatrixSnapshot
err := out.Print(cmd, matrix, f)
err := out.Print(cmd, matrix, parseFormat(cmd))
if err != nil {
log.Error("Unable to get config ", err)
return err
Expand Down
7 changes: 5 additions & 2 deletions cli/cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ func InitRemoveCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "remove",
Short: "Remove content from datahop network",
Long: `Add Long Description`,
Args: cobra.MinimumNArgs(1),
Long: `
"The commend is used to remove file/content from the
datahop network by a simple tag"
`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if comm.LitePeer == nil || !comm.LitePeer.IsOnline() {
return errors.New("daemon not running")
Expand Down
4 changes: 3 additions & 1 deletion cli/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ func InitStopCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "stop",
Short: "Stop datahop daemon",
Long: `Add Long Description`,
Long: `
"The commend is used to stop datahop daemon"
`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Printf("Daemon Stopped")
comm.Cancel()
Expand Down
4 changes: 3 additions & 1 deletion cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ func InitVersionCmd(comm *common.Common) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Datahop cli version",
Long: `Add Long Description`,
Long: `
"The commend is used to get cli version"
`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(version.CliVersion)
},
Expand Down
6 changes: 5 additions & 1 deletion cli/datahop.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ var (
rootCmd = &cobra.Command{
Use: "datahop",
Short: "This is datahop cli client",
Long: `Add Long Description`,
Long: `
The Datahop CLI client gives access to datahop
network through a CLI Interface.
`,
}
SockPath = "uds.sock"
log = logging.Logger("cmd")
Expand Down Expand Up @@ -72,6 +75,7 @@ func main() {
cmd.InitGetCmd(comm),
cmd.InitVersionCmd(comm),
cmd.InitMatrixCmd(comm),
cmd.InitializeDocCommand(comm),
)

for _, i := range allCommands {
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
Expand Down Expand Up @@ -774,6 +775,7 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down Expand Up @@ -944,7 +946,6 @@ golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPI
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
Expand Down

0 comments on commit 81b7146

Please sign in to comment.