• R/O
  • HTTP
  • SSH
  • HTTPS

bashlib-develop: Commit

開発中の bashlib


Commit MetaInfo

Revisiond15cc2029e4543216ac34558ff38f69333047436 (tree)
Zeit2011-10-04 23:42:57
AutorYour Name <you@exam...>
CommiterYour Name

Log Message

add InputOption_func

Ändern Zusammenfassung

Diff

Binary files a/document/bashlib.svg and b/document/bashlib.svg differ
--- a/sample/Menu.sh
+++ b/sample/Menu.sh
@@ -6,7 +6,7 @@
66
77 if [ -e "~/reset_env.sh" ]; then source "~/reset_env.sh" > /dev/null ;fi
88
9-export g_WritableFolders=( "$PWD" )
9+g_WritableFolders=( "$PWD" )
1010
1111 #//(end of export)
1212
--- a/scriptlib/bashlib.sh
+++ b/scriptlib/bashlib.sh
@@ -35,6 +35,8 @@ function CallMain_func()
3535 esac' DEBUG
3636 set +e
3737
38+ GetAbsPath_func "${g_Arguments[0]}" ; g_Arguments[0]="$g_Ret"
39+
3840 while TryStart_func; do
3941
4042 Main_func "" "AppKey4293"
@@ -289,6 +291,7 @@ function InputPath_func()
289291 local base_path
290292 local is_file_exist_opt
291293 local is_folder_exist_opt
294+ local is_not_exist_opt
292295 local len
293296 local ret
294297 local arguments
@@ -330,36 +333,54 @@ function InputPath_func()
330333
331334 Attr_func options "ChkFileExists" ; is_file_exist_opt="$g_Ret"
332335 Attr_func options "ChkFolderExists" ; is_folder_exist_opt="$g_Ret"
336+ Attr_func options "ChkNotExists" ; is_not_exist_opt="$g_Ret"
337+
338+ if [ "$is_not_exist_opt" == "1" ];then
339+ Assert_func '"$is_file_exist_opt" != "1"'
340+ Assert_func '"$is_folder_exist_opt" != "1"'
341+ fi
333342
334- if [ x"$is_file_exist_opt" == x"" -a x"$is_folder_exist_opt" == x"" ];then
343+ if [ x"$is_file_exist_opt" == x"" -a \
344+ x"$is_folder_exist_opt" == x"" -a \
345+ x"$is_not_exist_opt" == x"" ];then
335346 ret="$input_path"
336347 break
337348 fi
338349
339- if [ "$is_file_exist_opt" == "1" ];then
350+ if [ "$is_not_exist_opt" == "1" ];then
340351 if [ -f "$input_path" ]; then
352+ echo "すでにファイルが存在しています。" >&2
353+ elif [ -d "$input_path" ]; then
354+ echo "すでにフォルダーが存在しています。" >&2
355+ else
341356 ret="$input_path"
342357 break
343358 fi
344- fi
345-
346- if [ "$is_folder_exist_opt" == "1" ];then
347- if [ -d "$input_path" ]; then
348- ret="$input_path"
349- break
359+ else
360+ if [ "$is_file_exist_opt" == "1" ];then
361+ if [ -f "$input_path" ]; then
362+ ret="$input_path"
363+ break
364+ fi
350365 fi
351- fi
352366
353- if [ "$is_file_exist_opt" == "1" ];then
354367 if [ "$is_folder_exist_opt" == "1" ];then
355- echo "ファイルまたはフォルダーが見つかりません。" >&2
368+ if [ -d "$input_path" ]; then
369+ ret="$input_path"
370+ break
371+ fi
372+ fi
373+
374+ if [ "$is_file_exist_opt" == "1" ];then
375+ if [ "$is_folder_exist_opt" == "1" ];then
376+ echo "ファイルまたはフォルダーが見つかりません。" >&2
377+ else
378+ echo "ファイルが見つかりません。" >&2
379+ fi
356380 else
357- echo "ファイルが見つかりません。" >&2
381+ echo "フォルダーが見つかりません。" >&2
358382 fi
359- else
360- echo "フォルダーが見つかりません。" >&2
361383 fi
362-
363384 echo "$input_path" >&2
364385 fi
365386 fi
@@ -561,6 +582,77 @@ function InputCommand_func()
561582
562583
563584 #//*********************************************************************
585+#// <<< [InputOption_func] >>>
586+#//*********************************************************************
587+function InputOption_func()
588+{
589+ local name__
590+ local key__
591+ local left__
592+ local right__
593+ local comments__
594+ local i__
595+ local is_err__
596+
597+ local Options__
598+ $declare_AssociativeArrayClass option__
599+
600+ GetLongOptions_func Options__ option__ "$@" #//[out] arguments__, option__
601+ Attr_func option__ comment
602+ ArrayClass.fromCSV_method comments__ "$g_Ret" #//[out] comments__
603+
604+ SetAutoInputFromMainArg_func
605+
606+ while true ;do
607+
608+ #// finish auto input
609+ if [ "$g_AutoInput_ArgsNextIndex" -ge "${#g_AutoInput_Args[@]}" -a \
610+ "$g_AutoInput_ArgsNextIndex" -ge "2" -a \
611+ "$is_err__" != "1" ];then
612+ break
613+ fi
614+
615+ echo ""
616+ echo "現在のオプション設定:"
617+ i__=0
618+ for name__ in "${Options__[@]}" ;do
619+ eval echo "--$name__="'"\"$'"$name__"'\" ${comments__[$i__]}"'
620+ i__=$(( $i__ + 1 ))
621+ done ; done_func $?
622+ echo "Enter または . :設定完了"
623+ Input_func "オプションを入力してください(例:--${Options__[0]}=\"abc\"、--flag)>"
624+ key__="$g_Ret"
625+ if [ x"$key__" == x"" -o x"$key__" == x"." ];then break ;fi
626+
627+ if [ "${key__:0:2}" == "--" ];then
628+ key__="${key__:2}"
629+ elif [ "${key__:0:1}" == "-" ];then
630+ key__="${key__:1}"
631+ fi
632+ LeftOfStr_func "$key__" "=" ; left__="$g_Ret"
633+ if [ "$key__" == "$left__" ];then
634+ right__="1"
635+ else
636+ RightOfStr_func "$key__" "=" ; eval right__="$g_Ret"
637+ fi
638+
639+ for name__ in "${Options__[@]}" ;do
640+ if [ "$name__" == "$left__" ];then
641+ SetOutput_func $name__ "$right__"
642+ unset left__
643+ break
644+ fi
645+ done ; done_func $?
646+ if [ "$left__" != "" ];then
647+ echo "オプション $left__ はありません。"
648+ is_err__="1"
649+ fi
650+ done ; done_func $?
651+}
652+
653+
654+
655+#//*********************************************************************
564656 #// <<< [sudo_func] >>>
565657 #//*********************************************************************
566658 function sudo_func()
--- a/test/T_Menu.sh
+++ b/test/T_Menu.sh
@@ -17,6 +17,8 @@ function Main_func()
1717 T_NewSh_func "$@"
1818 T_Extract_sth_func "$@"
1919 T_chmod_x_func "$@"
20+ T_InputCommandOpt_func "$@"
21+ T_InputOptionAuto_func "$@"
2022 else
2123 $g_FuncName "$@"
2224 fi
@@ -213,6 +215,34 @@ function T_InputCommandOpt_NoMenuCaption_func()
213215
214216
215217
218+#//*********************************************************************
219+#// <<< [T_InputOptionAuto_func] >>>
220+#//*********************************************************************
221+function T_InputOptionAuto_func()
222+{
223+ EchoTestStart_func ${FUNCNAME[0]}
224+
225+ ./T_Menu.sh --T_InputOptionAuto_Sub_func --value="abc" --no_value
226+}
227+
228+function T_InputOptionAuto_Sub_func()
229+{
230+ local value="default"
231+ local no_value="0"
232+ local no_option="0"
233+
234+ ArrayClass.remove_method g_Arguments 1
235+
236+ InputOption_func value no_value no_option
237+
238+ Assert_func '"$value" == "abc"'
239+ Assert_func '"$no_value" == "1"'
240+ Assert_func '"$no_option" == "0"'
241+}
242+
243+
244+
245+
216246
217247
218248
--- a/test/T_Str.sh
+++ b/test/T_Str.sh
@@ -48,6 +48,7 @@ function Main_func()
4848 T_GetLongOptions_func "$@"
4949 T_local_func "$@"
5050 T_SetOutputAsArray_func "$@"
51+ T_Arguments_func "$@"
5152 fi
5253 else
5354 $g_FuncName "$@"
@@ -1149,7 +1150,17 @@ function T_SetOutputAsArraySub_func()
11491150
11501151
11511152
1153+#//*********************************************************************
1154+#// <<< [T_Arguments_func] >>>
1155+#//*********************************************************************
1156+function T_Arguments_func()
1157+{
1158+ EchoTestStart_func ${FUNCNAME[0]}
1159+ Assert_func '"${g_Arguments[0]}" == "$PWD/T_Str.sh"'
1160+}
1161+
11521162
1163+
11531164
11541165
11551166
--- a/test/T_UI_Manually.sh
+++ b/test/T_UI_Manually.sh
@@ -14,6 +14,7 @@ function Main_func()
1414 if [ "$g_FuncName" == "" ]; then
1515 echo T_InputPath_func
1616 echo T_InputCommand_func
17+ echo T_InputOption_func
1718 echo T_NewShFolder_func
1819 echo T_ColorText_func
1920 echo T_Pause_func
@@ -38,6 +39,7 @@ function T_InputPath_func()
3839 Error_func "このテストは、$HOME/bashlib に bashlib を配置されていることを想定しています。"
3940 fi
4041
42+
4143 if true; then #//(skip)
4244
4345 #//=== Test Main : ChkFolderExists
@@ -45,7 +47,7 @@ function T_InputPath_func()
4547 echo "2. nofile と入力して、警告&再入力されることを確認してください。"
4648 echo "3. Test.sh と入力して、警告&再入力されることを確認してください。"
4749 echo "4. ~ と入力できることを確認してください。"
48- InputPath_func "入力してください。>" --ChkFolderExists ; path="$g_Ret"
50+ InputPath_func "フォルダーのパス >" --ChkFolderExists ; path="$g_Ret"
4951 Assert_func "$path" == "$HOME"
5052 echo "Pass."
5153
@@ -59,7 +61,16 @@ function T_InputPath_func()
5961 echo "2. nofile と入力して、警告&再入力されることを確認してください。"
6062 echo "3. ans と入力して、警告&再入力されることを確認してください。"
6163 echo "4. Test.sh と入力できることを確認してください。"
62- InputPath_func "入力してください。>" --ChkFileExists ; path="$g_Ret"
64+ InputPath_func "ファイルのパス >" --ChkFileExists ; path="$g_Ret"
65+ echo "Pass."
66+
67+
68+ #//=== Test Main : ChkNotExists
69+ echo "1. Test.sh と入力して、警告&再入力されることを確認してください。"
70+ echo "2. ~ と入力して、警告&再入力されることを確認してください。"
71+ echo "3. nofile と入力できることを確認してください。"
72+ InputPath_func "何もないパス >" --ChkNotExists ; path="$g_Ret"
73+ Assert_func "$path" == "$g_StartInPath/nofile"
6374 echo "Pass."
6475
6576
@@ -142,6 +153,47 @@ function T_InputCommandError_func()
142153
143154
144155 #//*********************************************************************
156+#// <<< [T_InputOption_func] >>>
157+#//*********************************************************************
158+function T_InputOption_func()
159+{
160+ local work="space"
161+ local comment="nothing"
162+
163+ ArrayClass.remove_method g_Arguments 1
164+
165+ echo ""
166+ echo "■ work に abc を設定して、設定を完了してください。"
167+ InputOption_func work comment --comment=" ワーク, コメント"
168+
169+ echo "work=$work"
170+ Assert_func '"$work" == "abc"'
171+ Assert_func '"$comment" == "nothing"'
172+
173+
174+ ./T_UI_Manually.sh --T_InputOption_Sub_func --value="abc" ?
175+}
176+
177+
178+function T_InputOption_Sub_func()
179+{
180+ local value="default"
181+
182+ echo_line_func
183+ echo "自動入力にエラーがあったときのテスト。オプション入力モードの中に留まること。"
184+ echo "オプション入力モードの中では、すぐに設定終了してください。"
185+ Pause_func
186+
187+ ArrayClass.remove_method g_Arguments 1
188+
189+ InputOption_func value
190+
191+ Assert_func '"$value" == "abc"'
192+}
193+
194+
195+
196+#//*********************************************************************
145197 #// <<< [T_NewShFolder_func] >>>
146198 #//*********************************************************************
147199 function T_NewShFolder_func()
Show on old repository browser