Skip to content

Commit adbd0a0

Browse files
committed
feat: Enhance diff_command.sh with debug option and improved parameter validation
1 parent f46890d commit adbd0a0

2 files changed

Lines changed: 67 additions & 18 deletions

File tree

action.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@ description: |
55
author: ProjectAJ14
66

77
branding:
8-
icon: maximize # GitHub action icon
9-
color: blue # GitHub action color theme
8+
icon: maximize
9+
color: blue
1010

1111
inputs:
1212
command:
1313
description: The Flutter command to execute (e.g., test, build, analyze)
14-
required: false
15-
default: flutter analyze
14+
required: true
1615
type: string
1716
use-melos:
1817
description: Whether to execute the command using Melos for mono-repo support
1918
required: false
20-
default: true
21-
type: boolean
19+
default: 'false'
20+
type: string
21+
debug:
22+
description: Enable debug output for troubleshooting
23+
required: false
24+
default: 'false'
25+
type: string
2226

2327
runs:
2428
using: composite
@@ -39,6 +43,6 @@ runs:
3943
shell: bash
4044
run: |
4145
$GITHUB_ACTION_PATH/src/diff_command.sh \
42-
-p \
4346
-n '${{ inputs.command }}' \
44-
-f '${{ inputs.use-melos }}'
47+
-f '${{ inputs.use-melos }}' \
48+
${{ inputs.debug == 'true' && '-p' || '' }}

src/diff_command.sh

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,70 @@
11
#!/bin/bash
22

3-
# Usage: ./diff_command.sh <COMMAND> <USE_MELOS>
3+
# Script: diff_command.sh
4+
# Description: Executes Flutter commands with optional Melos support
5+
# Usage: ./diff_command.sh -n <command> -f <use_melos>
6+
#
7+
# Options:
8+
# -n Flutter command to execute
9+
# -f Use Melos (true/false)
10+
# -p Print debug information
11+
# -h Show this help message
412

513
set -e # Exit on any error
614

7-
COMMAND=$1
8-
USE_MELOS=${2:-false} # Use provided value or default to false if not specified
15+
# Initialize variables with defaults
16+
COMMAND=""
17+
USE_MELOS="false"
18+
DEBUG=false
919

20+
# Function to display usage information
21+
show_usage() {
22+
echo "Usage: $0 [-n command] [-f use_melos] [-p] [-h]"
23+
echo "Options:"
24+
echo " -n Flutter command to execute"
25+
echo " -f Use Melos (true/false)"
26+
echo " -p Print debug information"
27+
echo " -h Show this help message"
28+
exit 1
29+
}
30+
31+
# Parse command line options
32+
while getopts "n:f:ph" opt; do
33+
case $opt in
34+
n) COMMAND="$OPTARG" ;;
35+
f) USE_MELOS="$OPTARG" ;;
36+
p) DEBUG=true ;;
37+
h) show_usage ;;
38+
?) show_usage ;;
39+
esac
40+
done
1041

1142
# Validate required parameters
1243
if [ -z "$COMMAND" ]; then
13-
echo "Error: COMMAND is required"
14-
exit 1
44+
echo "Error: Command (-n) is required"
45+
show_usage
1546
fi
1647

17-
# Validate optional parameters
18-
19-
if [ "$USE_MELOS" != true ] && [ "$USE_MELOS" != false ]; then
20-
echo "Error: USE_MELOS must be 'true' or 'false'"
21-
exit 1
48+
# Validate USE_MELOS parameter
49+
USE_MELOS=$(echo "$USE_MELOS" | tr '[:upper:]' '[:lower:]') # Convert to lowercase
50+
if [ "$USE_MELOS" != "true" ] && [ "$USE_MELOS" != "false" ]; then
51+
echo "Error: Use Melos (-f) must be 'true' or 'false'"
52+
show_usage
2253
fi
2354

55+
# Debug output if requested
56+
if [ "$DEBUG" = true ]; then
57+
echo "Configuration:"
58+
echo "- Command: $COMMAND"
59+
echo "- Use Melos: $USE_MELOS"
60+
fi
2461

62+
# Execute command
2563
echo "Running command: $COMMAND"
64+
if [ "$USE_MELOS" = "true" ]; then
65+
echo "Using Melos for execution"
66+
# Add Melos-specific command execution here
67+
else
68+
# Add standard command execution here
69+
eval "$COMMAND"
70+
fi

0 commit comments

Comments
 (0)