@cryptotaxi247 / kubo / commits / 286d93503

add quieter option to name publish

Added a quieter/Q option to 'name publish' that, consistent with 'add', only outputs the value that was published. License: MIT Signed-off-by: Rob Deutsch <rdeutschob@gmail.com>

rob-deutsch committed Sep 20, 2018 at 13:35 UTC 286d935036e7d1417e931212ed52ecf6ed5c808f
2 files changed +41 -2
core/commands/name/publish.go
+10 -2
@@ -12,7 +12,7 @@ import (
12 e "github.com/ipfs/go-ipfs/core/commands/e"
13 keystore "github.com/ipfs/go-ipfs/keystore"
14
15 - "gx/ipfs/QmPXR4tNdLbp8HsZiPMjpsgqphX9Vhw2J6Jh5MKH2ovW3D/go-ipfs-cmds"
15 + cmds "gx/ipfs/QmPXR4tNdLbp8HsZiPMjpsgqphX9Vhw2J6Jh5MKH2ovW3D/go-ipfs-cmds"
16 crypto "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
17 peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
18 "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
@@ -32,6 +32,7 @@ const (
32 lifeTimeOptionName = "lifetime"
33 ttlOptionName = "ttl"
34 keyOptionName = "key"
35 + quieterOptionName = "quieter"
36 )
37
38 var PublishCmd = &cmds.Command{
@@ -86,6 +87,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
87 cmdkit.BoolOption(allowOfflineOptionName, "When offline, save the IPNS record to the the local datastore without broadcasting to the network instead of simply failing."),
88 cmdkit.StringOption(ttlOptionName, "Time duration this record should be cached for (caution: experimental)."),
89 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"),
90 + cmdkit.BoolOption(quieterOptionName, "Q", "Write only final hash."),
91 },
92 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
93 n, err := cmdenv.GetNode(env)
@@ -161,7 +163,13 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
163 return e.TypeErr(entry, v)
164 }
165
164 - _, err := fmt.Fprintf(w, "Published to %s: %s\n", entry.Name, entry.Value)
166 + var err error
167 + quieter, _ := req.Options[quieterOptionName].(bool)
168 + if quieter {
169 + _, err = fmt.Fprintln(w, entry.Name)
170 + } else {
171 + _, err = fmt.Fprintf(w, "Published to %s: %s\n", entry.Name, entry.Value)
172 + }
173 return err
174 }),
175 },
test/sharness/t0100-name.sh
+31
@@ -33,6 +33,29 @@ test_expect_success "resolve output looks good" '
33 test_cmp expected2 output
34 '
35
36 +# test publishing with -Q option
37 +
38 +
39 +test_expect_success "'ipfs name publish --quieter' succeeds" '
40 + PEERID=`ipfs id --format="<id>"` &&
41 + test_check_peerid "${PEERID}" &&
42 + ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
43 +'
44 +
45 +test_expect_success "pubrmlish --quieter output looks good" '
46 + echo "${PEERID}" >expected1 &&
47 + test_cmp expected1 publish_out
48 +'
49 +
50 +test_expect_success "'ipfs name resolve' succeeds" '
51 + ipfs name resolve "$PEERID" >output
52 +'
53 +
54 +test_expect_success "resolve output looks good" '
55 + printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
56 + test_cmp expected2 output
57 +'
58 +
59 # now test with a path
60
61 test_expect_success "'ipfs name publish --allow-offline' succeeds" '
@@ -102,6 +125,14 @@ test_expect_success "publish output has the correct error" '
125 grep "argument \"ipfs-path\" is required" publish_out
126 '
127
128 +test_expect_success "'ipfs name publish' fails" '
129 + printf '' | test_expect_code 1 ipfs name publish -Q --allow-offline >publish_out 2>&1
130 +'
131 +
132 +test_expect_success "publish output has the correct error" '
133 + grep "argument \"ipfs-path\" is required" publish_out
134 +'
135 +
136 test_expect_success "'ipfs name publish --help' succeeds" '
137 ipfs name publish --help
138 '