Skip to content

Commit 68a0d0f

Browse files
author
Dark Decoy
committed
Updated help menu and example for info command
Add json format option to info command Fixed issue with returning all parts of the metadata Updated help menu and example for info command Add json format option to info command Fixed issue with returning all parts of the metadata Signed-off-by: Dark Decoy <[email protected]>
1 parent defeac8 commit 68a0d0f

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

bin/hedgedoc

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Commands:
7070
history [--json]
7171
View the current logged in user's list of accessed notes.
7272
73+
info <note_id> [--json]
74+
View the metadata for a given note on the server.
75+
7376
Config:
7477
Configuration is set via environment variables (e.g. in ~/.bashrc or shell).
7578
@@ -107,6 +110,8 @@ Usage examples:
107110
\$ $SCRIPTNAME profile
108111
\$ $SCRIPTNAME history
109112
\$ $SCRIPTNAME history --json
113+
\$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ
114+
\$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ --json
110115
"
111116

112117

@@ -177,6 +182,75 @@ function import_note() {
177182
echo "$note_id"
178183
}
179184

185+
function info_note() {
186+
local note_id="$1"
187+
local json="$2"
188+
189+
if [[ ! "$note_id" ]]; then
190+
echo "Error: You must specify an export type and note id to export." >&2
191+
echo "" >&2
192+
echo "Usage: $SCRIPTNAME info <note_id> [--json]" >&2
193+
echo "For usage exmaples, see: $SCRIPTNAME help" >&2
194+
return 2
195+
fi
196+
197+
local json="$2"
198+
199+
if [[ ! "$note_id" ]]; then
200+
echo "Error: You must specify an export type and note id to export." >&2
201+
echo "" >&2
202+
echo "Usage: $SCRIPTNAME info <note_id> [--json]" >&2
203+
echo "For usage exmaples, see: $SCRIPTNAME help" >&2
204+
return 2
205+
fi
206+
207+
if [[ "$json" == "--json" ]]
208+
then
209+
210+
curl \
211+
--silent \
212+
--cookie "$HEDGEDOC_COOKIES_FILE" \
213+
"${HEDGEDOC_SERVER}/$note_id/info"
214+
215+
if [[ "$json" == "--json" ]]
216+
then
217+
218+
curl \
219+
--silent \
220+
--cookie "$HEDGEDOC_COOKIES_FILE" \
221+
"${HEDGEDOC_SERVER}/$note_id/info"
222+
223+
else
224+
225+
response="$(
226+
curl \
227+
--silent \
228+
--cookie "$HEDGEDOC_COOKIES_FILE" \
229+
"${HEDGEDOC_SERVER}/$note_id/info" \
230+
| jq '.title, .description, .viewcount, .createtime, .updatetime')
231+
)"
232+
233+
SAVEIFS=$IFS
234+
IFS=$'\n'
235+
metadata=( $response )
236+
IFS=$SAVEIFS
237+
238+
for ((i=0; i<${#metadata[@]}; i++))
239+
do
240+
241+
temp=${metadata[$i]}
242+
temp=${temp// /-}
243+
244+
metadata[$i]=${temp//\"/ }
245+
246+
done
247+
248+
echo ${metadata[@]}
249+
250+
fi
251+
252+
}
253+
180254
function export_note() {
181255
local export_type="${1#--}" note_id="${2:-}" output_path="${3:-}"
182256

@@ -392,6 +466,9 @@ function main() {
392466
echo "$help_str"
393467
return 0
394468
;;
469+
info)
470+
info_note "${1:-}" "${2:-}"
471+
;;
395472
import|import-as)
396473
import_note "${1:-}" "${2:-}"
397474
;;
@@ -436,4 +513,3 @@ fi
436513
if [[ "${1:-}" != "--import" ]]; then
437514
main "$@" || exit $?
438515
fi
439-

0 commit comments

Comments
 (0)