-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
135 lines (120 loc) · 3.07 KB
/
Copy pathrun.sh
File metadata and controls
135 lines (120 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env bash
set -euo pipefail
# Run the CLI or GUI project for development.
# Defaults to CLI when no target is selected.
# Behavior:
# - Builds the project: dotnet build <proj> -c <Configuration>
# - Prefers to run the built DLL via: dotnet <path-to-dll> -- <app-args>
# - Falls back to: dotnet run --project <proj> -c <Configuration> -- <app-args>
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
CLI_PROJECT="$PROJECT_ROOT/src/SshAgentEcho.Cli/SshAgentEcho.Cli.csproj"
GUI_PROJECT="$PROJECT_ROOT/src/SshAgentEcho.Gui/SshAgentEcho.Gui.csproj"
CONFIGURATION="Debug"
usage() {
cat <<'EOF'
Usage: ./run.sh [OPTION] [-- <app-args>]
Run the project. When no target is selected the script defaults to the CLI project.
Options:
--cli Run the CLI project (default)
--gui Run the GUI project
-c, --config Configuration (Debug|Release). Defaults to Debug
-h, --help Show this help message
Examples:
./run.sh --cli -- --print
./run.sh --gui
EOF
}
# Parse args (basic)
TARGET=""
POS_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--cli)
TARGET="cli"
shift
;;
--gui)
TARGET="gui"
shift
;;
-c|--config)
CONFIGURATION="${2:-}"
if [[ -z "$CONFIGURATION" ]]; then
echo "Error: missing value for $1" >&2
exit 2
fi
shift 2
;;
-h|--help)
usage
exit 0
;;
--)
shift
POS_ARGS+=("$@")
break
;;
*)
# If the user provided a positional 'cli' or 'gui'
if [[ -z "$TARGET" && ("$1" == "cli" || "$1" == "gui") ]]; then
TARGET="$1"
shift
else
POS_ARGS+=("$1")
shift
fi
;;
esac
done
# If nothing selected, default to CLI
if [[ -z "$TARGET" ]]; then
echo "ℹ️ No target selected; defaulting to CLI."
TARGET="cli"
fi
run_project() {
local project_path="$1"
shift
local args=("$@")
echo "🔧 Building project: $project_path"
dotnet build "$project_path" -c "$CONFIGURATION"
# Try to locate the built DLL
local project_dir
project_dir=$(dirname "$project_path")
local proj_name
proj_name=$(basename "$project_path" .csproj)
local search_dir="$project_dir/bin/$CONFIGURATION"
local dll_path
if [[ -d "$search_dir" ]]; then
dll_path=$(find "$search_dir" -type f -name "$proj_name.dll" -print -quit || true)
fi
if [[ -n "$dll_path" ]]; then
echo "🔧 Running DLL with dotnet: $dll_path"
if [[ ${#args[@]} -gt 0 ]]; then
dotnet "$dll_path" -- "${args[@]}"
else
dotnet "$dll_path"
fi
return $?
fi
# Fallback to dotnet run
echo "🔧 Running project (fallback): $project_path"
if [[ ${#args[@]} -gt 0 ]]; then
dotnet run --project "$project_path" -c "$CONFIGURATION" -- "${args[@]}"
else
dotnet run --project "$project_path" -c "$CONFIGURATION"
fi
return $?
}
case "$TARGET" in
cli)
run_project "$CLI_PROJECT" "${POS_ARGS[@]:-}"
;;
gui)
run_project "$GUI_PROJECT" "${POS_ARGS[@]:-}"
;;
*)
echo "Unknown target: $TARGET" >&2
exit 2
;;
esac