瀏覽代碼

base-files: fix rc.common help alignment

This commit introduces a new function `extra_command` to better format
the help text without having to calculate the indentation in every startup
script that wants to add a new command. So far it looks weird and is not
formatted correctly on some startup scripts.

After using the new `extra_command` wrapper the alignement looks correctly.

And if the indentation is not sufficient in the future, this can be
changed in the function extra_command at a central location.

Signed-off-by: Florian Eckert <[email protected]>
Florian Eckert 5 年之前
父節點
當前提交
1a69f50dc6
共有 2 個文件被更改,包括 25 次插入15 次删除
  1. 1 1
      package/base-files/Makefile
  2. 24 14
      package/base-files/files/etc/rc.common

+ 1 - 1
package/base-files/Makefile

@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 
 PKG_NAME:=base-files
 PKG_NAME:=base-files
-PKG_RELEASE:=233
+PKG_RELEASE:=234
 PKG_FLAGS:=nonshared
 PKG_FLAGS:=nonshared
 
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/

+ 24 - 14
package/base-files/files/etc/rc.common

@@ -62,20 +62,24 @@ depends() {
 	return 0
 	return 0
 }
 }
 
 
+EXTRA_HELP=""
+EXTRA_COMMANDS="boot shutdown depends"
+extra_command() {
+	local cmd="$1"
+	local help="$2"
+
+	local extra="$(printf "%-16s%s" "${cmd}" "${help}")"
+	EXTRA_HELP="${EXTRA_HELP}\t${extra}\n"
+	EXTRA_COMMANDS="${EXTRA_COMMANDS} ${cmd}"
+}
+
 help() {
 help() {
 	cat <<EOF
 	cat <<EOF
 Syntax: $initscript [command]
 Syntax: $initscript [command]
 
 
 Available commands:
 Available commands:
-	start	Start the service
-	stop	Stop the service
-	restart	Restart the service
-	reload	Reload configuration files (or restart if service does not implement reload)
-	enable	Enable service autostart
-	disable	Disable service autostart
-	enabled	Check if service is started on boot
-$EXTRA_HELP
 EOF
 EOF
+	echo -e "$EXTRA_HELP"
 }
 }
 
 
 # for procd
 # for procd
@@ -103,14 +107,20 @@ service_running() {
 
 
 ${INIT_TRACE:+set -x}
 ${INIT_TRACE:+set -x}
 
 
+extra_command "start" "Start the service"
+extra_command "stop" "Stop the service"
+extra_command "restart" "Restart the service"
+extra_command "reload" "Reload configuration files (or restart if service does not implement reload)"
+extra_command "enable" "Enable service autostart"
+extra_command "disable" "Disable service autostart"
+extra_command "enabled" "Check if service is started on boot"
+
 . "$initscript"
 . "$initscript"
 
 
 [ -n "$USE_PROCD" ] && {
 [ -n "$USE_PROCD" ] && {
-	EXTRA_COMMANDS="${EXTRA_COMMANDS} running status trace"
-	EXTRA_HELP="\
-	running	Check if service is running
-	status	Service status
-${EXTRA_HELP}"
+	extra_command "running" "Check if service is running"
+	extra_command "status" "Service status"
+	extra_command "trace" "Start with syscall trace"
 
 
 	. $IPKG_INSTROOT/lib/functions/procd.sh
 	. $IPKG_INSTROOT/lib/functions/procd.sh
 	basescript=$(readlink "$initscript")
 	basescript=$(readlink "$initscript")
@@ -165,6 +175,6 @@ ${EXTRA_HELP}"
 	}
 	}
 }
 }
 
 
-ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
+ALL_COMMANDS="${EXTRA_COMMANDS}"
 list_contains ALL_COMMANDS "$action" || action=help
 list_contains ALL_COMMANDS "$action" || action=help
 $action "$@"
 $action "$@"