Skip to content

Commit 08261dc

Browse files
authored
Merge pull request #20 from attogram/fix/trending-report-and-verbose-mode
Fix trending report order and add verbose mode
2 parents 25d970a + c5b73b6 commit 08261dc

10 files changed

Lines changed: 101 additions & 81 deletions

File tree

dashboard.sh

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ _error() {
4141
printf '[ERROR] %s\n' "$1" >&2
4242
}
4343

44-
REPORTER_TO_RUN=""
45-
REPORTER_ARGS=()
44+
OVERVIEW_TO_RUN=""
45+
OVERVIEW_ARGS=()
4646

4747
usage() {
4848
echo "Usage: $(basename "$0") [options] [module]"
49-
echo " or: $(basename "$0") -r <reporter> [reporter_options]"
49+
echo " or: $(basename "$0") -o <overview> [overview_options]"
5050
echo
5151
echo "Options:"
5252
echo " -f, --format <format> Set the output format for module runs."
5353
echo " Supported formats: ${VALID_FORMATS[*]}"
54-
echo " -r, --reporter <name> Run a specific reporter."
54+
echo " -o, --overview <name> Run a specific overview."
55+
echo " -v, --verbose Enable verbose (debug) mode."
5556
echo " -h, --help Display this help message."
5657
echo
5758
echo "To save a data collection report, redirect the output to a file:"
@@ -66,17 +67,17 @@ usage() {
6667
done
6768
echo " ${modules[*]}"
6869
echo
69-
echo "Available reporters:"
70-
local reporters=()
71-
for reporter in "${SCRIPT_DIR}/reporters"/*; do
72-
if [ -x "$reporter" ]; then
73-
reporters+=("$(basename "$reporter" .sh)")
70+
echo "Available overviews:"
71+
local overviews=()
72+
for overview in "${SCRIPT_DIR}/overviews"/*.sh; do
73+
if [ -x "$overview" ]; then
74+
overviews+=("$(basename "$overview" .sh)")
7475
fi
7576
done
76-
echo " ${reporters[*]}"
77+
echo " ${overviews[*]}"
7778
echo
7879
echo "If a module name (e.g., 'github') is provided, only that module will be run."
79-
echo "If a reporter is specified with -r, it will be run with any subsequent arguments."
80+
echo "If an overview is specified with -o, it will be run with any subsequent arguments."
8081
}
8182

8283
_debug "$DASHBOARD_NAME v$DASHBOARD_VERSION"
@@ -86,16 +87,20 @@ _debug 'parsing command-line arguments'
8687
while [[ $# -gt 0 ]]; do
8788
key="$1"
8889
case $key in
89-
-r|--reporter)
90-
REPORTER_TO_RUN="$2"
90+
-o|--overview)
91+
OVERVIEW_TO_RUN="$2"
9192
shift 2
92-
REPORTER_ARGS=("$@")
93-
break # Stop parsing, the rest of the args are for the reporter
93+
OVERVIEW_ARGS=("$@")
94+
break # Stop parsing, the rest of the args are for the overview
9495
;;
9596
-f|--format)
9697
FORMAT="$2"
9798
shift 2
9899
;;
100+
-v|--verbose)
101+
DASHBOARD_DEBUG=1
102+
shift
103+
;;
99104
-h|--help)
100105
usage
101106
exit 0
@@ -115,27 +120,27 @@ done
115120

116121
# --- Main Execution Flow ----------------------------------------------------
117122

118-
if [ -n "$REPORTER_TO_RUN" ]; then
119-
# --- Reporter Execution -------------------------------------------------
120-
_debug "Attempting to run reporter: $REPORTER_TO_RUN"
121-
REPORTER_PATH="${SCRIPT_DIR}/reporters/${REPORTER_TO_RUN}.sh"
122-
if [ ! -f "$REPORTER_PATH" ]; then
123+
if [ -n "$OVERVIEW_TO_RUN" ]; then
124+
# --- Overview Execution -------------------------------------------------
125+
_debug "Attempting to run overview: $OVERVIEW_TO_RUN"
126+
OVERVIEW_PATH="${SCRIPT_DIR}/overviews/${OVERVIEW_TO_RUN}.sh"
127+
if [ ! -f "$OVERVIEW_PATH" ]; then
123128
# try without .sh extension for convenience
124-
REPORTER_PATH="${SCRIPT_DIR}/reporters/${REPORTER_TO_RUN}"
125-
if [ ! -f "$REPORTER_PATH" ]; then
126-
_error "Error: Reporter '${REPORTER_TO_RUN}' not found."
129+
OVERVIEW_PATH="${SCRIPT_DIR}/overviews/${OVERVIEW_TO_RUN}"
130+
if [ ! -f "$OVERVIEW_PATH" ]; then
131+
_error "Error: Overview '${OVERVIEW_TO_RUN}' not found."
127132
exit 1
128133
fi
129134
fi
130135

131-
if [ ! -x "$REPORTER_PATH" ]; then
132-
_error "Error: Reporter '${REPORTER_TO_RUN}' is not executable."
136+
if [ ! -x "$OVERVIEW_PATH" ]; then
137+
_error "Error: Overview '${OVERVIEW_TO_RUN}' is not executable."
133138
exit 1
134139
fi
135140

136-
_debug "Executing reporter '$REPORTER_PATH' with args: ${REPORTER_ARGS[*]}"
141+
_debug "Executing overview '$OVERVIEW_PATH' with args: ${OVERVIEW_ARGS[*]}"
137142
# shellcheck source=/dev/null
138-
"$REPORTER_PATH" "${REPORTER_ARGS[@]}"
143+
"$OVERVIEW_PATH" "${OVERVIEW_ARGS[@]}"
139144

140145
else
141146
# --- Module Data Collection ---------------------------------------------
@@ -169,6 +174,9 @@ else
169174
fi
170175

171176
generate_report() {
177+
if [ ${#OUTPUTS[@]} -eq 0 ]; then
178+
return
179+
fi
172180
# The OUTPUTS array contains TSV data from the modules.
173181
# We now format it based on the user's requested FORMAT.
174182

@@ -344,7 +352,11 @@ else
344352
fi
345353
done
346354

347-
generate_report
355+
if [ ${#OUTPUTS[@]} -eq 0 ]; then
356+
echo "No data collected. Use --verbose for more details."
357+
else
358+
generate_report
359+
fi
348360
fi
349361

350362
_debug 'Done.'
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
# Reporters
1+
# Overviews
22

3-
Reporters are scripts that analyze the historical data collected by the modules. While the modules are responsible for _gathering_ data, reporters are responsible for _interpreting_ it.
3+
Overviews are scripts that analyze the historical data collected by the modules. While the modules are responsible for _gathering_ data, overviews are responsible for _interpreting_ it.
44

5-
## How to Run a Reporter
5+
## How to Run an Overview
66

7-
You can run any reporter using the `-r` flag on the main `dashboard.sh` script:
7+
You can run any overview using the `-o` flag on the main `dashboard.sh` script:
88

99
```bash
10-
./dashboard.sh -r <reporter_name> [reporter_options]
10+
./dashboard.sh -o <overview_name> [overview_options]
1111
```
1212

13-
For example, to run the `top-stars` reporter, you would use:
13+
For example, to run the `top-stars` overview, you would use:
1414

1515
```bash
16-
./dashboard.sh -r top-stars
16+
./dashboard.sh -o top-stars
1717
```
1818

19-
Some reporters accept their own arguments, which you can pass after the reporter's name:
19+
Some overviews accept their own arguments, which you can pass after the overview's name:
2020

2121
```bash
22-
./dashboard.sh -r top-stars 5
22+
./dashboard.sh -o top-stars 5
2323
```
2424

25-
## Available Reporters
25+
## Available Overviews
2626

27-
Here is a list of the currently available reporters.
27+
Here is a list of the currently available overviews.
2828

2929
### `trending`
3030

31-
The `trending` reporter shows the change in each metric over a period of time, but it only includes metrics that have actually changed. It reads all the `.tsv` report files from the `reports/` directory and calculates the difference between the first and last recorded values for each metric, filtering out any that have a change of zero.
31+
The `trending` overview shows the change in each metric over a period of time, but it only includes metrics that have actually changed. It reads all the `.tsv` report files from the `reports/` directory and calculates the difference between the first and last recorded values for each metric, filtering out any that have a change of zero.
3232

3333
**Usage:**
3434

3535
```bash
36-
./dashboard.sh -r trending [days]
36+
./dashboard.sh -o trending [days]
3737
```
3838

3939
- **`[days]`** (optional): The number of days of history to analyze.
@@ -57,12 +57,12 @@ Change Last Value First Value Metrics
5757

5858
### `top-stars`
5959

60-
The `top-stars` reporter finds the most recent report file and lists the top repositories by their star count.
60+
The `top-stars` overview finds the most recent report file and lists the top repositories by their star count.
6161

6262
**Usage:**
6363

6464
```bash
65-
./dashboard.sh -r top-stars [count]
65+
./dashboard.sh -o top-stars [count]
6666
```
6767

6868
- **`[count]`** (optional): The number of top repositories to display. Defaults to 10.
@@ -76,14 +76,14 @@ Rank Stars Repository
7676
1 1 attogram/dashboard
7777
```
7878

79-
## Creating Your Own Reporter
79+
## Creating Your Own Overview
8080

81-
You can easily create your own reporter by adding a new executable shell script to the `reporters/` directory.
81+
You can easily create your own overview by adding a new executable shell script to the `overviews/` directory.
8282

83-
A reporter script should:
83+
An overview script should:
8484

85-
1. Be placed in the `reporters/` directory.
86-
2. Be executable (`chmod +x reporters/my_reporter.sh`).
85+
1. Be placed in the `overviews/` directory.
86+
2. Be executable (`chmod +x overviews/my_overview.sh`).
8787
3. Read data from the `.tsv` files in the `reports/` directory. The path to the reports directory can be found relative to the script's own location: `REPORTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../reports"`.
8888
4. Parse its own arguments if needed.
8989
5. Print its analysis to standard output.

docs/dashboard-script.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The Main Script (`dashboard.sh`)
22

3-
The `dashboard.sh` script is the main entry point for the application. It serves as an orchestrator, responsible for parsing arguments, loading configuration, and running modules for data collection, or running reporters for data analysis.
3+
The `dashboard.sh` script is the main entry point for the application. It serves as an orchestrator, responsible for parsing arguments, loading configuration, and running modules for data collection, or running overviews for data analysis.
44

55
## Usage
66

@@ -10,16 +10,17 @@ To collect data from modules:
1010
./dashboard.sh [options] [module]
1111
```
1212

13-
To run a reporter:
13+
To run an overview:
1414

1515
```
16-
./dashboard.sh -r <reporter_name> [reporter_options]
16+
./dashboard.sh -o <overview_name> [overview_options]
1717
```
1818

1919
### Options
2020

2121
- `-f, --format <format>`: (For module runs only) Specify the output format. See [Output Formats](./dashboard-output-formats.md) for a full list of supported formats. If not provided, the default is `tsv`.
22-
- `-r, --reporter <name>`: Run a specific reporter from the `reporters/` directory. Any subsequent arguments will be passed to the reporter script.
22+
- `-o, --overview <name>`: Run a specific overview from the `overviews/` directory. Any subsequent arguments will be passed to the overview script.
23+
- `-v, --verbose`: Enable verbose (debug) mode, which prints detailed messages about the script's execution to standard error.
2324
- `-h, --help`: Display a help message with usage information and exit.
2425

2526
### Arguments
@@ -32,7 +33,7 @@ The script has two main modes of operation: data collection and reporting.
3233

3334
### Data Collection Mode
3435

35-
This is the default mode when the `-r` flag is not used.
36+
This is the default mode when the `-o` flag is not used.
3637

3738
1. **Argument Parsing**: It parses command-line options (`-f`, `-h`) and an optional module name.
3839

@@ -46,10 +47,10 @@ This is the default mode when the `-r` flag is not used.
4647

4748
5. **Report Generation**: The script collects the output from each executed module. For structured formats like `json`, `xml`, and `html`, it wraps the collected outputs with the appropriate root elements. For simpler formats like `plain` or `csv`, it concatenates the outputs. The final report is printed to standard output, which can be redirected to a file.
4849

49-
### Reporter Mode
50+
### Overview Mode
5051

51-
This mode is triggered by the `-r` flag.
52+
This mode is triggered by the `-o` flag.
5253

53-
1. **Argument Parsing**: The script looks for the `-r` flag. When found, it takes the next argument as the reporter's name. All following arguments are passed directly to the reporter.
54+
1. **Argument Parsing**: The script looks for the `-o` flag. When found, it takes the next argument as the overview's name. All following arguments are passed directly to the overview.
5455

55-
2. **Reporter Execution**: The script looks for an executable file with the given name in the `reporters/` directory and runs it, passing along any reporter-specific arguments. The output of the reporter is printed to standard output.
56+
2. **Overview Execution**: The script looks for an executable file with the given name in the `overviews/` directory and runs it, passing along any overview-specific arguments. The output of the overview is printed to standard output.

modules/crypto.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ get_provider() {
5757
# --- Provider Implementations ---
5858

5959
fetch_from_local_btc() {
60-
if ! command -v bitcoin-cli &> /dev/null; then return 1; fi
61-
local btc_info wallet_name balance display_name
60+
if ! command -v bitcoin-cli &> /dev/null; then
61+
echo "[ERROR] bitcoin-cli not found. Please install Bitcoin Core and ensure bitcoin-cli is in your PATH." >&2
62+
return 1
63+
fi
64+
local btc_info
6265
btc_info=$(bitcoin-cli getwalletinfo 2>/dev/null)
63-
if [ $? -ne 0 ]; then return 1; fi
66+
if [ $? -ne 0 ]; then
67+
echo "[ERROR] bitcoin-cli command failed. Please ensure your Bitcoin node is running and configured correctly." >&2
68+
return 1
69+
fi
70+
local wallet_name balance display_name
6471
wallet_name=$(echo "$btc_info" | jq -r '.walletname')
6572
balance=$(echo "$btc_info" | jq -r '.balance')
6673
display_name="local node ($wallet_name)"

overviews/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Overviews
2+
3+
This directory contains scripts that analyze the historical data collected by the modules.
4+
5+
## Available Overviews
6+
7+
Here is a list of the currently available overviews:
8+
9+
- **`trending`**: Shows the change in each metric over a period of time.
10+
- **`top-stars`**: Lists the top repositories by their star count from the most recent report.
11+
12+
## Creating Your Own Overview
13+
14+
You can easily create your own overview by adding a new executable shell script to this directory. An overview script should be executable and placed in this directory.
15+
16+
For more detailed documentation, please see the main project documentation in the `docs/` directory.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ END {
106106
(
107107
echo -e "Change\tLast\tFirst\tmodule\tchannels\tnamespace"
108108
echo -e "------\t----\t-----\t------\t--------\t---------"
109-
sort -k1,1nr
109+
sort -k1,1gr
110110
)

reporters/README.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/crypto.bats

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ teardown() {
5555
CRYPTO_WALLET_BTC="test_btc_address" \
5656
bash modules/crypto.sh
5757
[ "$status" -eq 0 ]
58+
echo "Blockcypher Output: $output"
5859
[[ "$output" =~ .*${tab}crypto${tab}balance${tab}crypto.BTC.test_btc_address.BTC${tab}0.12345678$ ]]
5960
}
6061

@@ -64,6 +65,7 @@ teardown() {
6465
CRYPTO_WALLET_ETH="test_eth_address" \
6566
bash modules/crypto.sh
6667
[ "$status" -eq 0 ]
68+
echo "Covalent Output: $output"
6769
[[ "$output" =~ .*${tab}crypto${tab}balance${tab}crypto.ETH.test_eth_address.ETH${tab}1.234$ ]]
6870
}
6971

test/dashboard.bats

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ teardown() {
3333
@test "dashboard.sh --help should show usage" {
3434
run ./dashboard.sh --help
3535
echo "$output" | grep -q "Usage: dashboard.sh \[options\] \[module\]"
36-
echo "$output" | grep -q -- "-r, --reporter <name>"
36+
echo "$output" | grep -q -- "-o, --overview <name>"
3737
echo "$output" | grep -q "Available modules:"
38-
echo "$output" | grep -q "Available reporters:"
38+
echo "$output" | grep -q "Available overviews:"
3939
}
4040

4141
# --- Integration Tests for Centralized Output Formatting ---

0 commit comments

Comments
 (0)