Browse Source

Add custom import function mkit_import()

To minimize code needed to import a module
Alois Mahdal 7 years ago
parent
commit
e103c6bca8
4 changed files with 32 additions and 17 deletions
  1. 2
    2
      src/include/build.sh
  2. 1
    1
      src/include/facts.sh
  3. 27
    12
      src/include/mkit.sh
  4. 2
    2
      src/include/release.sh

+ 2
- 2
src/include/build.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
-. "$MKIT_DIR/include/ini.sh"   || die "cannot import ini.sh"
4
-. "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
3
+mkit_import ini
4
+mkit_import facts
5
 
5
 
6
 
6
 
7
 _build1() {
7
 _build1() {

+ 1
- 1
src/include/facts.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
-. "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
3
+mkit_import ini
4
 
4
 
5
 git_bool() {
5
 git_bool() {
6
     #
6
     #

+ 27
- 12
src/include/mkit.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
-. "$MKIT_DIR/include/build.sh"  || die "cannot import build.sh"
4
-. "$MKIT_DIR/include/deploy.sh" || die "cannot import deploy.sh"
5
-. "$MKIT_DIR/include/release.sh" || die "cannot import release.sh"
6
-. "$MKIT_DIR/include/ini.sh"    || die "cannot import ini.sh"
3
+die() {
4
+    #
5
+    # Exit with message and non-zero exit status
6
+    #
7
+    echo "fatal: $*" >&2
8
+    exit 4
9
+}
10
+
11
+mkit_import() {
12
+    #
13
+    # Import mkit module $1.sh
14
+    #
15
+    # Check for module, source it and die with reasonable message if needed.
16
+    #
17
+    local modname=$1
18
+    local modpath
19
+    modpath="$MKIT_DIR/include/$modname.sh"
20
+    test -f "$modpath" || die "no such module: $modpath"
21
+    bash -n "$modpath" || die "bad syntax: $modpath"
22
+    #shellcheck disable=SC1090
23
+    . "$modpath" || die "failed to import: $modname"
24
+}
25
+
26
+mkit_import build
27
+mkit_import deploy
28
+mkit_import release
29
+mkit_import ini
7
 
30
 
8
 _valid_targets() {
31
 _valid_targets() {
9
     #
32
     #
49
     done
72
     done
50
 }
73
 }
51
 
74
 
52
-die() {
53
-    #
54
-    # Exit with message and non-zero exit status
55
-    #
56
-    echo "fatal: $*" >&2
57
-    exit 4
58
-}
59
-
60
 _compver() {
75
 _compver() {
61
     #
76
     #
62
     # True if version $1 matches our version
77
     # True if version $1 matches our version

+ 2
- 2
src/include/release.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
-. "$MKIT_DIR/include/ini.sh"   || die "cannot import ini.sh"
4
-. "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
3
+mkit_import ini
4
+mkit_import facts
5
 
5
 
6
 _bump_version() {
6
 _bump_version() {
7
     #
7
     #