-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global --cid-base option and enable it for most commands.
This does it on ther server side for most commands. This also adds a global --output-cidv1 option. License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
- Loading branch information
Showing
21 changed files
with
532 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmdenv | ||
|
||
import ( | ||
cidenc "gx/ipfs/QmVjZoEZg2oxXGFGjbD28x3gGN6ALHAW6BN2LKRUcaJ21i/go-cidutil/cidenc" | ||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds" | ||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit" | ||
mbase "gx/ipfs/QmekxXDhCxCJRNuzmHreuaT3BsuJcsjcXWNrtV9C8DRHtd/go-multibase" | ||
) | ||
|
||
var OptionCidBase = cmdkit.StringOption("cid-base", "Multi-base encoding used for version 1 CIDs in output.") | ||
var OptionOutputCidV1 = cmdkit.BoolOption("output-cidv1", "Upgrade CID version 0 to version 1 in output.") | ||
|
||
// ProcCidBase processes the `cid-base` and `output-cidv1` options and | ||
// returns a encoder to use based on those parameters. | ||
func ProcCidBase(req *cmds.Request) (cidenc.Encoder, error) { | ||
base, _ := req.Options["cid-base"].(string) | ||
upgrade, upgradeDefined := req.Options["output-cidv1"].(bool) | ||
|
||
var e cidenc.Encoder = cidenc.Default | ||
|
||
if base != "" { | ||
var err error | ||
e.Base, err = mbase.EncoderByName(base) | ||
if err != nil { | ||
return e, err | ||
} | ||
e.Upgrade = true | ||
} | ||
|
||
if upgradeDefined { | ||
e.Upgrade = upgrade | ||
} | ||
|
||
return e, nil | ||
} | ||
|
||
func CidBaseDefined(req *cmds.Request) bool { | ||
base, _ := req.Options["cid-base"].(string) | ||
return base != "" | ||
} | ||
|
||
// EnableCidBaseGlobal is a prerun function... | ||
func EnableCidBaseGlobal(req *cmds.Request, env cmds.Environment) error { | ||
enc, err := ProcCidBase(req) | ||
if err != nil { | ||
return err | ||
} | ||
cidenc.Default = enc | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.