OSDN Git Service

Some fixes about removing unecessary redo.
[portsreinstall/current.git] / lib / libcommand.sh
1 #!/bin/sh -e
2 # ==============================================================================
3 # portsreinstall library script
4 # - Interface of libraries for operations of commands as well as check of command line arguments -
5 # Copyright (C) 2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
6 # This software is distributed under the 2-Clause BSD License.
7 # ==============================================================================
8
9 # ============= Variables =============
10 COMMAND_MODE=do
11 COMMAND_SHIFT=0
12 COMMAND_OPERATION=
13 COMMAND_SAVE_DIR=
14 COMMAND_LOAD_FILE=
15 COMMAND_SHOW_SUBJECT=
16 COMMAND_DO_MODE=all
17 COMMAND_RESTART=
18 COMMAND_SHOW_OPTIONS=
19 COMMAND_SHOW_DEPTAG=
20 COMMAND_SHOW_LEVEL=
21 COMMAND_SHOW_KEYWORD=
22
23 # ============= Check the necessity of opening notice =============
24 command_all_chk_need_opening_notice ()
25 {
26         :
27 }
28
29 # ============= Check the number of following command line arguments (in case glob arguments are needed) =============
30 _command_parse_args__chk_glob_args ()
31 {
32         local nargs
33         nargs=$1
34         [ $nargs -gt 0 ] && return
35         message_echo "ERROR: No port glob is specified." >&2
36         exit 1
37 }
38
39 # ============= Check the number of following command line arguments (in case without arguments) =============
40 _command_parse_args__chk_no_arg ()
41 {
42         local nargs term_redundant_argument
43         nargs=$1
44         [ $nargs -eq 0 ] && return
45         term_redundant_argument='A redundant argument is'
46         [ $nargs -gt 1 ] && term_redundant_argument='Redundant arguments are'
47         message_echo "ERROR: $term_redundant_argument specified." >&2
48         exit 1
49 }
50
51 # ============= Execute command operations before getting the temporary database ready =============
52 command_all_exec_before_db_creation ()
53 {
54 }
55
56 # ============= Check and parse command line arguments =============
57 command_all_parse_args ()
58 {
59 }
60
61 # ============= Notify that option settings are reset =============
62 command_exec_without_pkgtools__notify_reset_options ()
63 {
64         [ $opt_no_opening_message = yes ] && return
65         message_echo "NOTE: Option settings are ignored (because of no effect) and reset."
66 }
67
68 # ============= Execute command operations which do not need package tools =============
69 command_all_exec_without_pkgtools ()
70 {
71 }
72
73
74 # ============= Notify that option settings are ignored because of no effect =============
75 _command_exec_irrespective_of_saved_options__notify_ignored_options ()
76 {
77         [ $opt_no_opening_message = yes ] && return
78         message_echo "NOTE: Option settings are ignored because they have no effect on this command."
79 }
80
81 # ============= Execute command operations which are irrespective of option settings =============
82 command_all_exec_irrespective_of_saved_options ()
83 {
84 }
85
86 # ============= Execute command operations which should be carried out just after completing the option settings =============
87 command_all_exec_just_after_option_settings ()
88 {
89         shift || :
90         case $COMMAND_MODE in
91         options )
92                 options_show_all
93                 exit
94                 ;;
95         esac
96 }
97
98 # ============= Execute command operations which should be done without upgrade of tools =============
99 command_all_exec_before_tools_upgrade ()
100 {
101 }
102
103 # ============= Execute command operations which must be done before the database construction =============
104 command_all_exec_command_specific_preconfiguration ()
105 {
106 }
107
108 # ============= Execute command operations of database construction =============
109 command_all_exec_build_database ()
110 {
111 }
112
113 # ============= Execute command operations which must be done before the main process =============
114 command_all_exec_before_main ()
115 {
116 }
117
118 # ============= Execute command operations as the main process =============
119 command_all_exec_main ()
120 {
121 }