# shellcheck shell=bash disable=SC2154,2034
___x_cmd_shodan_query_tag(){
    local X_help_cmd='x help -m shodan query tag';   help:arg:parse
    shodan:arg:format:all

    "___x_cmd_shodan_query_tag___${format}"
}

___x_cmd_shodan_query_tag___app(){
    local data; data=$( ___x_cmd_shodan_query_tag___csv )     || shodan:data:ret
    ___x_cmd_pipevar data  x csv app --return print
}

___x_cmd_shodan_query_tag___csv(){
    local data; data=$( ___x_cmd_shodan_query_tag___json )     || shodan:data:ret
    ___x_cmd_pipevar data ___x_cmd_shodan_query_tag___parse_json2csv
}

___x_cmd_shodan_query_tag___tsv(){
    local data; data=$( ___x_cmd_shodan_query_tag___csv )      || shodan:data:ret
    ___x_cmd_pipevar data
}

___x_cmd_shodan_query_tag___json(){
    local data; data="$( ___x_cmd_shodan_query_tag___raw )"    || shodan:data:ret
    ___x_cmd_pipevar data
}

___x_cmd_shodan_query_tag___raw(){
    ___x_cmd_shodan_ourl get /shodan/query/tags
}

___x_cmd_shodan_query_tag___parse_json2csv(){
    local matches=
    x jo env . .matches
    [ -n "$matches" ] || N=shodan M="Not found data" log:ret:1
    printf "%s" "$matches" | x ja 2c .count .value |\
        x csv header --add  Count Value
}

