ipfs.go 1.64 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
	"fmt"
5 6
	"os"

Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
7 8
	"github.com/gonuts/flag"
	"github.com/jbenet/commander"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
9 10
	config "github.com/jbenet/go-ipfs/config"
	core "github.com/jbenet/go-ipfs/core"
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
11
	u "github.com/jbenet/go-ipfs/util"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
12 13
)

Juan Batiz-Benet's avatar
go lint  
Juan Batiz-Benet committed
14
// The IPFS command tree. It is an instance of `commander.Command`.
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28
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
29 30 31
    config        Manage configuration.
    version       Show ipfs version information.
    commands      List all available commands.
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
32 33 34

Advanced Commands:

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

Use "ipfs help <command>" for more information about a command.
`,
	Run: ipfsCmd,
	Subcommands: []*commander.Command{
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
41
		cmdIpfsAdd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
42
		cmdIpfsCat,
43
		cmdIpfsLs,
Juan Batiz-Benet's avatar
refs  
Juan Batiz-Benet committed
44
		cmdIpfsRefs,
45
		cmdIpfsConfig,
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
46 47
		cmdIpfsVersion,
		cmdIpfsCommands,
48
		cmdIpfsMount,
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
49 50 51 52 53 54 55 56 57
	},
	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
58
func main() {
59
	u.Debug = true
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
60 61 62
	err := CmdIpfs.Dispatch(os.Args[1:])
	if err != nil {
		if len(err.Error()) > 0 {
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
63
			fmt.Fprintf(os.Stderr, "ipfs %s: %v\n", os.Args[1], err)
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
64 65 66 67
		}
		os.Exit(1)
	}
	return
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
68
}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
69 70 71

func localNode() (*core.IpfsNode, error) {
	//todo implement config file flag
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
72
	cfg, err := config.Load("")
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
73 74 75 76 77 78
	if err != nil {
		return nil, err
	}

	return core.NewIpfsNode(cfg)
}