rpc: Input-from-stdin mode for bitcoin-cli#7550
Conversation
|
Brilliant idea! ACK laanwj@c97198d pavel$ echo -e "getblockhash\n0" | bitcoin-7550/src/bitcoin-cli -stdin
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
pavel$ |
|
Nice! |
src/bitcoin-cli.cpp
Outdated
There was a problem hiding this comment.
what about adding a magic work as ^D alternative? Something like "end" or "quit"?
There was a problem hiding this comment.
I've thought about that. The problem is that anything could be a valid argument. I've chosen the line-per-argument, until EOL to avoid that kind of escaping issues.
It's easy for scripting but yes for a user interface it's not very friendly.
master...laanwj:2016_02_cli_stdin is better in that regard, but what makes it an easier user interface is annoying/dangerous for scripting (as you'd have to quote ' "" etc to prevent one argument from spilling into the next)
There was a problem hiding this comment.
Maybe adding a little ">>>" prompt and or giving a one-line-help-instruction when using -stdin (something like "enter command, arguments and use Ctrl-D to quit/execute")?
Allow quitting over "quit()" and if "exit" or "quit" has been typed, show little help line?
Though, a simple one-line-help-message would probably do the job.
Python example:
:~ jonasschnelli$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:14)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exitThere was a problem hiding this comment.
That would be awesome for an "interactive mode" (see #3122), but -stdin is explicitly not meant to be that, it's just to have a way to input data (say, from scripts) that isn't exposed on the command line. Printing more text will make it harder to parse the output.
There was a problem hiding this comment.
Agree. Was nitpick territory anyway (does not affect my tested ACK I already gave).
There was a problem hiding this comment.
Right, for now, I've added a EOF/Ctrl-D mention to the -help message at least.
|
Tested ACK c97198db769954c4ad2b57eaf7e5335578badc00 Post-merge actions: add to the docs/release notes, maybe add a little test script (though, not sure if we have a test entry point for bitcoin-cli at all). |
Implements bitcoin#7442 by adding an option `-stdin` which reads additional arguments from stdin, one per line. For example ```bash echo -e "mysecretcode\n120" | src/bitcoin-cli -stdin walletpassphrase echo -e "walletpassphrase\nmysecretcode\n120" | src/bitcoin-cli -stdin ```
c97198d to
92bcca3
Compare
|
Re-ACK 92bcca3 |
29e1dfb [test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests (João Barbosa) ce379b4 [test] Replace check_output with low level version (João Barbosa) 232e3e8 [test] Add assert_raises_process_error to assert process errors (João Barbosa) 5c18a84 [test] Add support for custom arguments to TestNodeCLI (João Barbosa) e127494 [test] Improve assert_raises_jsonrpc docstring (João Barbosa) 7696841 Fix style in -stdin and -stdinrpcpass handling (João Barbosa) Pull request description: This patch adds tests for `bitcoin-cli` options `-stdin` (#7550) and `-stdinrpcpass` #10997. Tree-SHA512: fd8133f44876f2b5b41dfd3762b1988598f6b7bf13fb2385ad95876825d9c0b2b896ce4ea6eeb21012158e1f276907f155d37bb967198b609d2d3dddbfa334c1
CLI binary improvements Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#5936 - bitcoin/bitcoin#7550 - bitcoin/bitcoin#7989 - bitcoin/bitcoin#7957 - bitcoin/bitcoin#9067 - bitcoin/bitcoin#9220 Excludes any changes that affected the QT code.
…nal tests 29e1dfb [test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests (João Barbosa) ce379b4 [test] Replace check_output with low level version (João Barbosa) 232e3e8 [test] Add assert_raises_process_error to assert process errors (João Barbosa) 5c18a84 [test] Add support for custom arguments to TestNodeCLI (João Barbosa) e127494 [test] Improve assert_raises_jsonrpc docstring (João Barbosa) 7696841 Fix style in -stdin and -stdinrpcpass handling (João Barbosa) Pull request description: This patch adds tests for `bitcoin-cli` options `-stdin` (bitcoin#7550) and `-stdinrpcpass` bitcoin#10997. Tree-SHA512: fd8133f44876f2b5b41dfd3762b1988598f6b7bf13fb2385ad95876825d9c0b2b896ce4ea6eeb21012158e1f276907f155d37bb967198b609d2d3dddbfa334c1
…nal tests 29e1dfb [test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests (João Barbosa) ce379b4 [test] Replace check_output with low level version (João Barbosa) 232e3e8 [test] Add assert_raises_process_error to assert process errors (João Barbosa) 5c18a84 [test] Add support for custom arguments to TestNodeCLI (João Barbosa) e127494 [test] Improve assert_raises_jsonrpc docstring (João Barbosa) 7696841 Fix style in -stdin and -stdinrpcpass handling (João Barbosa) Pull request description: This patch adds tests for `bitcoin-cli` options `-stdin` (bitcoin#7550) and `-stdinrpcpass` bitcoin#10997. Tree-SHA512: fd8133f44876f2b5b41dfd3762b1988598f6b7bf13fb2385ad95876825d9c0b2b896ce4ea6eeb21012158e1f276907f155d37bb967198b609d2d3dddbfa334c1 remove duplicate method Signed-off-by: Pasta <[email protected]>
Implements #7442 by adding an option
-stdinwhich reads additional arguments from standard in, one per line.For example
This is the simplest implementation and avoids escaping issues by using newline as separator instead of space, I first had another implementation: laanwj@1f73b8e that reuses
parseCommandLinefrom the GUI debug console, but I think this is more useful in practice as most use of cli is probably script-driven.