Skip to content

Commit 1eb882e

Browse files
committed
CLI: cross-platform compatiblity
1 parent da3fe12 commit 1eb882e

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ $ avalanche-cli keystore delete-user -Y
132132
Since `avalance-cli` does not process the JSON reponses, it is recommended to use the excellent [`jq`] tool to handle them. For example:
133133

134134
```sh
135-
$ avalanche-cli info peers -Y | jq .result.peers[0]
135+
$ avalanche-cli info peers -YS | jq .result.peers[0]
136136
```
137137
```json
138138
{
@@ -144,6 +144,7 @@ $ avalanche-cli info peers -Y | jq .result.peers[0]
144144
"lastReceived": "2020-06-27T04:16:38+02:00"
145145
}
146146
```
147+
..where the `-S` (`--silent-rpc`) option tells the internal `curl` tool to not produce unnessary output, so we get the desired result from above. ;D
147148

148149
## [Admin API](https://docs.ava.network/v1.0/en/api/admin)
149150

avalanche-cli.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22
# shellcheck disable=SC1090,SC1091,SC2214,SC2231
33
###############################################################################
4-
CLI_SCRIPT=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
5-
CLI_SCRIPT=$(cd "$CLI_SCRIPT" >/dev/null 2>&1 && pwd)
4+
CLI=$(dirname "${BASH_SOURCE[0]}")/$(dirname "$(readlink "${BASH_SOURCE[0]}")")
5+
CLI=$(cd "$CLI" >/dev/null 2>&1 && pwd)
66
###############################################################################
77

88
function cli {
@@ -29,9 +29,9 @@ function cli {
2929

3030
function cli_run {
3131
local cmd="$1" ;
32-
local cmd_path="$CLI_SCRIPT/cmd/$cmd" ;
32+
local cmd_path="$CLI/cmd/$cmd" ;
3333
local sub="$2" ;
34-
local sub_path="$CLI_SCRIPT/cmd/$cmd/$sub.sh" ;
34+
local sub_path="$CLI/cmd/$cmd/$sub.sh" ;
3535
if [ -d "$cmd_path" ] ; then
3636
if [ -f "$sub_path" ] ; then
3737
exec "$sub_path" "${@:3}" ;
@@ -63,7 +63,7 @@ function cli_supoptions {
6363
}
6464

6565
function cli_supcommands {
66-
for path in $CLI_SCRIPT/cmd/* ; do
66+
for path in $CLI/cmd/* ; do
6767
path="${path##*/}" ;
6868
printf '%s ' "$path" ;
6969
done
@@ -75,7 +75,7 @@ function cli_suboptions {
7575
}
7676

7777
function cli_subcommands {
78-
for path in $CLI_SCRIPT/cmd/"$1"/*.sh ; do
78+
for path in $CLI/cmd/"$1"/*.sh ; do
7979
if [[ ! "$path" =~ \.test\.sh$ ]] ; then
8080
path="${path##*/}" ;
8181
path="${path%.*}" ;
@@ -86,13 +86,13 @@ function cli_subcommands {
8686
}
8787

8888
function cli_usage {
89-
source "$CLI_SCRIPT/cli/help.sh" && \
89+
source "$CLI/cli/help.sh" && \
9090
printf '%s\n' "$(cli_help "$1" "$2")" ;
9191
}
9292

9393
function cli_version {
94-
source "$CLI_SCRIPT/cli/jq.sh" && \
95-
jq ".version" < "$CLI_SCRIPT/package.json" ;
94+
source "$CLI/cli/jq.sh" && \
95+
jq ".version" < "$CLI/package.json" ;
9696
}
9797

9898
###############################################################################

cli/rpc/post.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ function rpc_post {
2020
else
2121
if [ -n "$(command -v jq)" ] ; then
2222
if [ "$mime" == "content-type:application/json" ] ; then
23-
eval curl "${args}" --no-progress-meter | jq -c ;
23+
eval curl "${args}" | jq -c ;
2424
else
25-
eval curl "${args}" --no-progress-meter ;
25+
eval curl "${args}" ;
2626
fi
2727
else
28-
eval curl "${args}" --no-progress-meter ;
28+
eval curl "${args}" ;
2929
fi
3030
fi
3131
}

0 commit comments

Comments
 (0)