Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
330ee8c7
Commit
330ee8c7
authored
Oct 02, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added command struct for makeCommand
parent
2bd84312
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
27 deletions
+51
-27
cmd/ipfs/add.go
cmd/ipfs/add.go
+6
-1
cmd/ipfs/cat.go
cmd/ipfs/cat.go
+6
-1
cmd/ipfs/gen.go
cmd/ipfs/gen.go
+21
-22
cmd/ipfs/ls.go
cmd/ipfs/ls.go
+6
-1
cmd/ipfs/pin.go
cmd/ipfs/pin.go
+6
-1
cmd/ipfs/refs.go
cmd/ipfs/refs.go
+6
-1
No files found.
cmd/ipfs/add.go
View file @
330ee8c7
...
...
@@ -29,4 +29,9 @@ func init() {
cmdIpfsAdd
.
Flag
.
Bool
(
"r"
,
false
,
"add objects recursively"
)
}
var
addCmd
=
MakeCommand
(
"add"
,
[]
string
{
"r"
},
commands
.
Add
)
var
addCmd
=
makeCommand
(
command
{
name
:
"add"
,
args
:
1
,
flags
:
[]
string
{
"r"
},
cmdFn
:
commands
.
Add
,
})
cmd/ipfs/cat.go
View file @
330ee8c7
...
...
@@ -18,7 +18,12 @@ var cmdIpfsCat = &commander.Command{
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-cat"
,
flag
.
ExitOnError
),
}
var
catCmd
=
MakeCommand
(
"cat"
,
nil
,
commands
.
Cat
)
var
catCmd
=
makeCommand
(
command
{
name
:
"cat"
,
args
:
1
,
flags
:
nil
,
cmdFn
:
commands
.
Cat
,
})
/*
func catCmd(c *commander.Command, inp []string) error {
...
...
cmd/ipfs/gen.go
View file @
330ee8c7
package
main
import
(
"errors"
"fmt"
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/config"
"github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u
"github.com/jbenet/go-ipfs/util"
)
// CommanderFunc is a function that can be passed into the Commander library as
// command is the descriptor of an ipfs daemon command.
// Used with makeCommand to proxy over commands via the daemon.
type
command
struct
{
name
string
args
int
flags
[]
string
online
bool
cmdFn
commands
.
CmdFunc
}
// commanderFunc is a function that can be passed into the Commander library as
// a command handler. Defined here because commander lacks this definition.
type
C
ommanderFunc
func
(
*
commander
.
Command
,
[]
string
)
error
type
c
ommanderFunc
func
(
*
commander
.
Command
,
[]
string
)
error
//
M
akeCommand Wraps a commands.CmdFunc so that it may be safely run by the
//
m
akeCommand Wraps a commands.CmdFunc so that it may be safely run by the
// commander library
func
M
akeCommand
(
cmd
Name
string
,
expargs
[]
string
,
cmdFn
commands
.
CmdFunc
)
C
ommanderFunc
{
func
m
akeCommand
(
cmd
Desc
command
)
c
ommanderFunc
{
return
func
(
c
*
commander
.
Command
,
inp
[]
string
)
error
{
if
len
(
inp
)
<
1
{
if
len
(
inp
)
<
cmdDesc
.
args
{
u
.
POut
(
c
.
Long
)
return
nil
}
...
...
@@ -29,34 +37,25 @@ func MakeCommand(cmdName string, expargs []string, cmdFn commands.CmdFunc) Comma
return
err
}
confapi
,
err
:=
config
.
ReadConfigKey
(
confdir
+
"/config"
,
"Addresses.API"
)
if
err
!=
nil
{
return
err
}
apiaddr
,
ok
:=
confapi
.
(
string
)
if
!
ok
{
return
errors
.
New
(
"ApiAddress in config file was not a string"
)
}
cmd
:=
daemon
.
NewCommand
()
cmd
.
Command
=
cmd
N
ame
cmd
.
Command
=
cmd
Desc
.
n
ame
cmd
.
Args
=
inp
for
_
,
a
:=
range
expar
gs
{
for
_
,
a
:=
range
cmdDesc
.
fla
gs
{
cmd
.
Opts
[
a
]
=
c
.
Flag
.
Lookup
(
a
)
.
Value
.
Get
()
}
err
=
daemon
.
SendCommand
(
cmd
,
apiaddr
)
err
=
daemon
.
SendCommand
(
cmd
,
confdir
)
if
err
!=
nil
{
fmt
.
Printf
(
"Executing command locally: %s"
,
err
)
// Do locally
n
,
err
:=
localNode
(
confdir
,
fals
e
)
n
,
err
:=
localNode
(
confdir
,
cmdDesc
.
onlin
e
)
if
err
!=
nil
{
fmt
.
Println
(
"Local node creation failed."
)
return
err
}
return
cmdFn
(
n
,
cmd
.
Args
,
cmd
.
Opts
,
os
.
Stdout
)
return
cmdDesc
.
cmdFn
(
n
,
cmd
.
Args
,
cmd
.
Opts
,
os
.
Stdout
)
}
return
nil
}
...
...
cmd/ipfs/ls.go
View file @
330ee8c7
...
...
@@ -21,4 +21,9 @@ var cmdIpfsLs = &commander.Command{
Flag
:
*
flag
.
NewFlagSet
(
"ipfs-ls"
,
flag
.
ExitOnError
),
}
var
lsCmd
=
MakeCommand
(
"ls"
,
nil
,
commands
.
Ls
)
var
lsCmd
=
makeCommand
(
command
{
name
:
"ls"
,
args
:
1
,
flags
:
nil
,
cmdFn
:
commands
.
Ls
,
})
cmd/ipfs/pin.go
View file @
330ee8c7
...
...
@@ -23,4 +23,9 @@ func init() {
cmdIpfsPin
.
Flag
.
Int
(
"d"
,
1
,
"recursive depth"
)
}
var
pinCmd
=
MakeCommand
(
"pin"
,
[]
string
{
"r"
,
"d"
},
commands
.
Pin
)
var
pinCmd
=
makeCommand
(
command
{
name
:
"pin"
,
args
:
1
,
flags
:
[]
string
{
"r"
,
"d"
},
cmdFn
:
commands
.
Pin
,
})
cmd/ipfs/refs.go
View file @
330ee8c7
...
...
@@ -28,4 +28,9 @@ func init() {
cmdIpfsRefs
.
Flag
.
Bool
(
"u"
,
false
,
"unique: list each ref only once"
)
}
var
refCmd
=
MakeCommand
(
"refs"
,
[]
string
{
"r"
,
"u"
},
commands
.
Refs
)
var
refCmd
=
makeCommand
(
command
{
name
:
"refs"
,
args
:
1
,
flags
:
[]
string
{
"r"
,
"u"
},
cmdFn
:
commands
.
Refs
,
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment