ipfs.go 1.53 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
refmt  
Juan Batiz-Benet committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26
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
27 28 29
    config        Manage configuration.
    version       Show ipfs version information.
    commands      List all available commands.
Juan Batiz-Benet's avatar
refmt  
Juan Batiz-Benet committed
30 31 32

Advanced Commands:

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

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

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

	return core.NewIpfsNode(cfg)
}