Ver código fonte

Add greeter with exposed module

Split saturnin-demo to a double-package distribution, where one package
provides core saturnin-demo with its subcommands and the other provides
a Shellfu/Bash module saturnin_demo_greet.sh used by the first one.
Alois Mahdal 7 anos atrás
pai
commit
6c1727fab5

+ 3
- 0
mkit.ini Ver arquivo

@@ -33,6 +33,7 @@
33 33
     doc     = [ENV:PREFIX]/share/doc/saturnin-demo
34 34
     etc     = /etc/saturnin-demo
35 35
     etc_bc  = /etc/bash_completion.d
36
+    sfincb  = [ENV:PREFIX]/share/shellfu/include-bash
36 37
 
37 38
 [tokens]
38 39
     __SATURNIN_DATA_HOME__    = [ENV:XDG_DATA_HOME]/saturnin-demo
@@ -52,6 +53,8 @@
52 53
     etc_bc  = src/complete.bash              saturnin-demo.bash
53 54
     libexec = src/libexec/saturnin-demo-dump
54 55
     libexec = src/libexec/saturnin-demo-echo
56
+    libexec = src/libexec/saturnin-demo-greet
57
+    sfincb  = src/shellfu/saturnin_demo_greet.sh
55 58
     share   = src/help
56 59
     share   = src/ini.d
57 60
 

+ 17
- 0
packaging/debian/control Ver arquivo

@@ -20,6 +20,7 @@ Depends:
20 20
  shellfu-bash-pretty,
21 21
  shellfu-bash-saturnin (>= 0.4.8),
22 22
  shellfu-bash-saturnin (<< 5.0),
23
+ shellfu-bash-saturnin_demo,
23 24
 Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
24 25
  saturnin is Shellfu library that helps you easily build toolkit from
25 26
  various scripts that you may have lying around.  Instead of having a
@@ -30,4 +31,20 @@ Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
30 31
  This package contains a demo meta-command built with saturnin; you can
31 32
  also re-use the source as template for your new toolkit.
32 33
 
34
+Package: shellfu-bash-saturnin_demo
35
+Architecture: all
36
+Depends:
37
+ shellfu (>= 0.10),
38
+ shellfu (<< 0.11),
39
+ shellfu-bash-pretty,
40
+Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
41
+ saturnin is Shellfu library that helps you easily build toolkit from
42
+ various scripts that you may have lying around.  Instead of having a
43
+ herd of untamed undocumented and hard-to-share scripts, with help of
44
+ saturnin you can easily create and package a meta-command with a set
45
+ of discoverable and maintainable sub-commands.
46
+ .
47
+ This sub-package contains Shellfu/Bash modules used by
48
+ *saturnin-demo*.
49
+
33 50
 # control file built with MKit __MKIT_SELF_VERSION__

+ 2
- 1
packaging/debian/rules Ver arquivo

@@ -13,4 +13,5 @@ override_dh_auto_test:
13 13
 	make clean
14 14
 	make install PREFIX=/usr DESTDIR=TEST
15 15
 	make test \
16
-		PATH="$(shell pwd)/TEST/usr/bin:$(PATH)"
16
+		PATH="$(shell pwd)/TEST/usr/bin:$(PATH)" \
17
+		SHELLFU_PATH="$(shell pwd)/TEST/usr/share/shellfu/include-bash"

packaging/debian/install → packaging/debian/saturnin-demo.install Ver arquivo

@@ -2,6 +2,7 @@
2 2
 /usr/bin/saturnin-demo
3 3
 /usr/libexec/saturnin-demo/saturnin-demo-dump
4 4
 /usr/libexec/saturnin-demo/saturnin-demo-echo
5
+/usr/libexec/saturnin-demo/saturnin-demo-greet
5 6
 /usr/share/doc/saturnin-demo/README.md
6 7
 /usr/share/saturnin-demo/help
7 8
 /usr/share/saturnin-demo/ini.d/main/echo.ini

+ 1
- 0
packaging/debian/shellfu-saturnin_demo.install Ver arquivo

@@ -0,0 +1 @@
1
+/usr/share/shellfu/include-bash/saturnin_demo_greet.sh

+ 15
- 1
packaging/template.spec Ver arquivo

@@ -1,3 +1,4 @@
1
+%define sfincb %{_datadir}/shellfu/include-bash
1 2
 %define shellfu_req shellfu >= 0.10.4, shellfu < 0.11
2 3
 %define saturnin_req shellfu-bash-saturnin >= 0.4.10, shellfu-bash-saturnin < 0.5
3 4
 
@@ -14,6 +15,7 @@ BuildRequires:  %shellfu_req
14 15
 
15 16
 Requires:   %shellfu_req
16 17
 Requires:   %saturnin_req
18
+Requires:   shellfu-bash-saturnin_demo
17 19
 %description
18 20
 saturnin is Shellfu library that helps you easily build toolkit from
19 21
 various scripts that you may have lying around.  Instead of having a
@@ -24,6 +26,14 @@ of discoverable and maintainable sub-commands.
24 26
 This package contains a demo meta-command built with saturnin; you can
25 27
 also re-use the source as template for your new toolkit.
26 28
 
29
+%package -n shellfu-bash-saturnin_demo
30
+Summary: Shellfu/Bash modules for saturnin-demo
31
+Requires: %saturnin_req
32
+Requires: shellfu-bash
33
+Requires: shellfu-bash-pretty
34
+%description -n shellfu-bash-saturnin_demo
35
+This sub-package contains Shellfu/Bash modules used by *saturnin-demo*.
36
+
27 37
 %prep
28 38
 %setup -q
29 39
 
@@ -35,7 +45,8 @@ make %{?_smp_mflags} PREFIX=/usr
35 45
 
36 46
 %check
37 47
 make test \
38
-    PATH="%{buildroot}/%{_bindir}:$PATH"
48
+    PATH="%{buildroot}/%{_bindir}:$PATH" \
49
+    SHELLFU_PATH="%{buildroot}/%{sfincb}"
39 50
 
40 51
 %files
41 52
 %config %{_sysconfdir}/bash_completion.d/%{name}.bash
@@ -49,7 +60,10 @@ make test \
49 60
 %{_datadir}/%{name}/ini.d/main/echo.ini
50 61
 %{_libexecdir}/%{name}/%{name}-dump
51 62
 %{_libexecdir}/%{name}/%{name}-echo
63
+%{_libexecdir}/%{name}/%{name}-greet
52 64
 
65
+%files -n shellfu-bash-saturnin_demo
66
+%{sfincb}/saturnin_demo_greet.sh
53 67
 
54 68
 %changelog
55 69
 

+ 34
- 0
src/libexec/saturnin-demo-greet Ver arquivo

@@ -0,0 +1,34 @@
1
+#!/bin/bash
2
+
3
+. "$(sfpath)" || exit 3
4
+
5
+shellfu import pretty
6
+
7
+shellfu import saturnin_demo_greet
8
+
9
+usage() {
10
+    mkusage "$@" \
11
+        "-u [USER]" \
12
+        "[-w]" \
13
+      -c \
14
+        "-u [USER]    greet user USER or current user" \
15
+        "-w           greet the world (default mode)"
16
+}
17
+
18
+main() {
19
+    local mode=world
20
+    local user=
21
+    while true; do case $1 in
22
+        -u) mode=user; user=$2; break ;;
23
+        -w) mode=world; break ;;
24
+        "") break ;;
25
+        *) usage -w "unknown argument: $1" ;;
26
+    esac done
27
+    debug -v mode user
28
+    case $mode in
29
+        user)   saturnin_demo_greet__user "$user" ;;
30
+        world)  saturnin_demo_greet__world ;;
31
+    esac
32
+}
33
+
34
+main "$@"

+ 21
- 0
src/shellfu/saturnin_demo_greet.sh Ver arquivo

@@ -0,0 +1,21 @@
1
+#!/bin/bash
2
+
3
+shellfu import pretty
4
+
5
+saturnin_demo_greet__world() {
6
+    #
7
+    # Greet the world
8
+    #
9
+    think "greeting the world"
10
+    echos "Hello, world!"
11
+}
12
+
13
+saturnin_demo_greet__user() {
14
+    #
15
+    # Greet user $1 or $USER
16
+    #
17
+    local user=${1:-$USER}
18
+    debug -v user
19
+    think "greeting user: $user"
20
+    echos "Hello, $user!"
21
+}