Merge pull request #5494 from rob-deutsch/feat/publishquieter

add quieter option to name publish
This commit is contained in:
Steven Allen 2018-09-24 10:11:18 +00:00 committed by GitHub
commit ac53d3aaa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 2 deletions

View File

@ -12,7 +12,7 @@ import (
e "github.com/ipfs/go-ipfs/core/commands/e"
keystore "github.com/ipfs/go-ipfs/keystore"
"gx/ipfs/QmPXR4tNdLbp8HsZiPMjpsgqphX9Vhw2J6Jh5MKH2ovW3D/go-ipfs-cmds"
cmds "gx/ipfs/QmPXR4tNdLbp8HsZiPMjpsgqphX9Vhw2J6Jh5MKH2ovW3D/go-ipfs-cmds"
crypto "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
@ -32,6 +32,7 @@ const (
lifeTimeOptionName = "lifetime"
ttlOptionName = "ttl"
keyOptionName = "key"
quieterOptionName = "quieter"
)
var PublishCmd = &cmds.Command{
@ -86,6 +87,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
cmdkit.BoolOption(allowOfflineOptionName, "When offline, save the IPNS record to the the local datastore without broadcasting to the network instead of simply failing."),
cmdkit.StringOption(ttlOptionName, "Time duration this record should be cached for (caution: experimental)."),
cmdkit.StringOption(keyOptionName, "k", "Name of the key to be used or a valid PeerID, as listed by 'ipfs key list -l'. Default: <<default>>.").WithDefault("self"),
cmdkit.BoolOption(quieterOptionName, "Q", "Write only final hash."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
n, err := cmdenv.GetNode(env)
@ -161,7 +163,13 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
return e.TypeErr(entry, v)
}
_, err := fmt.Fprintf(w, "Published to %s: %s\n", entry.Name, entry.Value)
var err error
quieter, _ := req.Options[quieterOptionName].(bool)
if quieter {
_, err = fmt.Fprintln(w, entry.Name)
} else {
_, err = fmt.Fprintf(w, "Published to %s: %s\n", entry.Name, entry.Value)
}
return err
}),
},

View File

@ -33,6 +33,29 @@ test_expect_success "resolve output looks good" '
test_cmp expected2 output
'
# test publishing with -Q option
test_expect_success "'ipfs name publish --quieter' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
'
test_expect_success "pubrmlish --quieter output looks good" '
echo "${PEERID}" >expected1 &&
test_cmp expected1 publish_out
'
test_expect_success "'ipfs name resolve' succeeds" '
ipfs name resolve "$PEERID" >output
'
test_expect_success "resolve output looks good" '
printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
test_cmp expected2 output
'
# now test with a path
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
@ -102,6 +125,14 @@ test_expect_success "publish output has the correct error" '
grep "argument \"ipfs-path\" is required" publish_out
'
test_expect_success "'ipfs name publish' fails" '
printf '' | test_expect_code 1 ipfs name publish -Q --allow-offline >publish_out 2>&1
'
test_expect_success "publish output has the correct error" '
grep "argument \"ipfs-path\" is required" publish_out
'
test_expect_success "'ipfs name publish --help' succeeds" '
ipfs name publish --help
'