ipfs.go 1.63 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3
package main

import (
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
4 5 6
	"fmt"
	"github.com/gonuts/flag"
	"github.com/jbenet/commander"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
7 8
	config "github.com/jbenet/go-ipfs/config"
	core "github.com/jbenet/go-ipfs/core"
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
9 10
	u "github.com/jbenet/go-ipfs/util"
	"os"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
11 12
)

Juan Batiz-Benet's avatar
go lint  
Juan Batiz-Benet committed
13
// The IPFS command tree. It is an instance of `commander.Command`.
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27
var CmdIpfs = &commander.Command{
	UsageLine: "ipfs [<flags>] <command> [<args>]",
	Short:     "global versioned p2p merkledag file system",
	Long: `ipfs - global versioned p2p merkledag file system

Basic commands:

    add <path>    Add an object to ipfs.
    cat <ref>     Show ipfs object data.
    ls <ref>      List links from an object.
    refs <ref>    List link hashes from an object.

Tool commands:

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
28 29 30
    config        Manage configuration.
    version       Show ipfs version information.
    commands      List all available commands.
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
31 32 33

Advanced Commands:

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34
    mount         Mount an ipfs read-only mountpoint.
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
35 36 37 38 39

Use "ipfs help <command>" for more information about a command.
`,
	Run: ipfsCmd,
	Subcommands: []*commander.Command{
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
40
		cmdIpfsAdd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
41
		cmdIpfsCat,
42
		cmdIpfsLs,
Juan Batiz-Benet's avatar
refs  
Juan Batiz-Benet committed
43
		cmdIpfsRefs,
44
		cmdIpfsConfig,
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
45 46
		cmdIpfsVersion,
		cmdIpfsCommands,
47
		cmdIpfsMount,
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
48 49 50 51 52 53 54 55 56
	},
	Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError),
}

func ipfsCmd(c *commander.Command, args []string) error {
	u.POut(c.Long)
	return nil
}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
57
func main() {
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
58 59 60
	err := CmdIpfs.Dispatch(os.Args[1:])
	if err != nil {
		if len(err.Error()) > 0 {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
61
			fmt.Fprintf(os.Stderr, "ipfs %s: %v\n", os.Args[1], err)
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
62 63 64 65
		}
		os.Exit(1)
	}
	return
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
66
}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
67 68 69 70 71 72 73 74 75 76

func localNode() (*core.IpfsNode, error) {
	//todo implement config file flag
	cfg, err := config.LoadConfig("")
	if err != nil {
		return nil, err
	}

	return core.NewIpfsNode(cfg)
}