Skip to content

Commit 8415784

Browse files
committed
feat: 添加 --show-profile 显示指定套餐详情
- 显示 profile 名称、描述、图标 - 列出包含的软件列表 - 标记当前平台支持 (✓) 和不支持 (✗) - 统计支持/不支持的软件数量 - 帮助信息更新
1 parent 4fb7d24 commit 8415784

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

dist/quickstart.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Quickstart-PC - 一键配置新电脑
3535
--verbose, -v 显示详细调试信息
3636
--log-file FILE 将日志写入文件
3737
--list-profiles 列出所有可用套餐
38+
--show-profile KEY 显示指定套餐详情
3839
--help 显示此帮助信息
3940
HELPZH
4041
else
@@ -54,6 +55,7 @@ Options:
5455
--verbose, -v Show detailed debug info
5556
--log-file FILE Write logs to file
5657
--list-profiles List all available profiles
58+
--show-profile KEY Show profile details
5759
--help Show this help message
5860
HELPEN
5961
fi
@@ -66,6 +68,7 @@ AUTO_YES=false
6668
VERBOSE=false
6769
LOG_FILE=""
6870
LIST_PROFILES=false
71+
SHOW_PROFILE=""
6972
LANG_OVERRIDE=""
7073
CFG_PATH=""
7174
CFG_URL=""
@@ -79,6 +82,7 @@ while [[ $# -gt 0 ]]; do
7982
--verbose|-v) VERBOSE=true; shift ;;
8083
--log-file) LOG_FILE="$2"; shift 2 ;;
8184
--list-profiles) LIST_PROFILES=true; shift ;;
85+
--show-profile) SHOW_PROFILE="$2"; shift 2 ;;
8286
--lang) LANG_OVERRIDE="$2"; shift 2 ;;
8387
--cfg-path) CFG_PATH="$2"; shift 2 ;;
8488
--cfg-url) CFG_URL="$2"; shift 2 ;;
@@ -127,6 +131,78 @@ if [[ "$LIST_PROFILES" == "true" ]]; then
127131
exit 0
128132
fi
129133

134+
# --show-profile 在语言选择之前处理,默认英文输出
135+
if [[ -n "$SHOW_PROFILE" ]]; then
136+
# 检测 jq
137+
if ! command -v jq &>/dev/null; then
138+
if [[ "$(uname -s)" == "Darwin" ]]; then
139+
brew install jq 2>/dev/null
140+
else
141+
sudo apt install -y jq 2>/dev/null
142+
fi
143+
fi
144+
145+
CONFIG_FILE=$(mktemp /tmp/quickstart-config-XXXXXX.json)
146+
if [[ -n "$CFG_URL" ]]; then
147+
curl -fsSL --connect-timeout 10 --max-time 30 "$CFG_URL" -o "$CONFIG_FILE" 2>/dev/null
148+
elif [[ -n "$CFG_PATH" ]]; then
149+
cp "$CFG_PATH" "$CONFIG_FILE" 2>/dev/null
150+
else
151+
curl -fsSL --connect-timeout 10 --max-time 30 "$DEFAULT_CFG_URL" -o "$CONFIG_FILE" 2>/dev/null
152+
fi
153+
154+
if [[ -f "$CONFIG_FILE" ]] && jq empty "$CONFIG_FILE" 2>/dev/null; then
155+
# 检测当前平台
156+
current_os=""
157+
case "$OSTYPE" in
158+
msys*|mingw*|cygwin*|win*) current_os="win" ;;
159+
darwin*) current_os="mac" ;;
160+
linux*) current_os="linux" ;;
161+
esac
162+
163+
pname=$(jq -r ".profiles[\"$SHOW_PROFILE\"].name // \"\"" "$CONFIG_FILE")
164+
pdesc=$(jq -r ".profiles[\"$SHOW_PROFILE\"].desc // \"\"" "$CONFIG_FILE")
165+
picon=$(jq -r ".profiles[\"$SHOW_PROFILE\"].icon // \"\"" "$CONFIG_FILE")
166+
167+
if [[ -z "$pname" ]]; then
168+
echo "[ERROR] Profile '$SHOW_PROFILE' not found"
169+
rm -f "$CONFIG_FILE" 2>/dev/null
170+
exit 1
171+
fi
172+
173+
echo ""
174+
echo "Profile: ${picon} ${pname}"
175+
echo "Description: ${pdesc}"
176+
echo ""
177+
echo "Included software:"
178+
179+
supported=0
180+
unsupported=0
181+
while IFS= read -r sw; do
182+
[[ -z "$sw" ]] && continue
183+
sw_name=$(jq -r ".software[\"$sw\"].name // \"$sw\"" "$CONFIG_FILE")
184+
sw_cmd=$(jq -r ".software[\"$sw\"].$current_os // \"\"" "$CONFIG_FILE")
185+
186+
if [[ -n "$sw_cmd" ]]; then
187+
echo "$sw_name"
188+
((supported++))
189+
else
190+
echo "$sw_name (not supported on this platform)"
191+
((unsupported++))
192+
fi
193+
done < <(jq -r ".profiles[\"$SHOW_PROFILE\"].includes[]?" "$CONFIG_FILE")
194+
195+
echo ""
196+
echo "Summary: $supported supported, $unsupported unsupported on this platform"
197+
echo ""
198+
else
199+
echo "[ERROR] Failed to load configuration"
200+
fi
201+
202+
rm -f "$CONFIG_FILE" 2>/dev/null
203+
exit 0
204+
fi
205+
130206
# 日志系统
131207
log_to_file() {
132208
[[ -n "$LOG_FILE" ]] && echo "$*" >> "$LOG_FILE"

0 commit comments

Comments
 (0)