|
@@ -1,125 +0,0 @@
|
1
|
|
-Shellfu guidelines
|
2
|
|
-==================
|
3
|
|
-
|
4
|
|
-By Alois Mahdal
|
5
|
|
-
|
6
|
|
-
|
7
|
|
-UI/UX
|
8
|
|
------
|
9
|
|
-
|
10
|
|
-* Heavily prefer unix filter UI.
|
11
|
|
-
|
12
|
|
- If you can't do it with filtering, it could mean you should split your
|
13
|
|
- function anyway.
|
14
|
|
-
|
15
|
|
-* Even function can use dash options and even `usage()`.
|
16
|
|
-
|
17
|
|
-* Do not `think()` in functions.
|
18
|
|
-
|
19
|
|
-* Preferred capitalization in messages is:
|
20
|
|
-
|
21
|
|
- * all small for libs (debug/warn/die)
|
22
|
|
-
|
23
|
|
- * First cap for scripts
|
24
|
|
-
|
25
|
|
-* Message width:
|
26
|
|
-
|
27
|
|
- * think/warn/die: try hard to never exceed 72
|
28
|
|
-
|
29
|
|
- * debug: do what you must
|
30
|
|
-
|
31
|
|
- * always try to split message to fixed part, colon and *before* colon and
|
32
|
|
- the "data" part after the colon, e.g.:
|
33
|
|
-
|
34
|
|
- file missing: /var/run/media/somebody/some-medium/some-long/path
|
35
|
|
-
|
36
|
|
- instead of:
|
37
|
|
-
|
38
|
|
- file /var/run/media/somebody/some-medium/some-long/path is missing
|
39
|
|
-
|
40
|
|
- (even if you think that it will be short)
|
41
|
|
-
|
42
|
|
-
|
43
|
|
-API
|
44
|
|
----
|
45
|
|
-
|
46
|
|
-
|
47
|
|
-### Exit status ###
|
48
|
|
-
|
49
|
|
-* consider using `exit.sh`
|
50
|
|
-
|
51
|
|
-* do not use exit status to convey information other than
|
52
|
|
- success or error type
|
53
|
|
-
|
54
|
|
-* use 1 for "no", 2 for syntax error (if applicable), more
|
55
|
|
- otherwise; note that shellfu pretty.die uses 9 as a generic
|
56
|
|
- status
|
57
|
|
-
|
58
|
|
-
|
59
|
|
-### Arguments ###
|
60
|
|
-
|
61
|
|
-* Reserved options are
|
62
|
|
-
|
63
|
|
- * `-q|--quiet`, to turn off verbosity,
|
64
|
|
- * `-v|--verbose`, to turn on verbosity,
|
65
|
|
- * and `-d|--debug` to turn on debug output (stderr).
|
66
|
|
-
|
67
|
|
-### Variables ###
|
68
|
|
-
|
69
|
|
-* module "bar" has implicitly reserved namespace "SHELLFU_BAR* and "__FOO_BAR*"
|
70
|
|
-
|
71
|
|
-* few exceptions exist like SHELLFU_DEBUG, where Shellfu itself reserves
|
72
|
|
- a module name
|
73
|
|
-
|
74
|
|
-* always consider
|
75
|
|
-
|
76
|
|
- SHELLFU_BAR_BAZ=${SHELLFU_BAR_BAZ:-value}
|
77
|
|
-
|
78
|
|
- over
|
79
|
|
-
|
80
|
|
- SHELLFU_BAR_BAZ="value"
|
81
|
|
-
|
82
|
|
- since in the first case user can set this (in-line when calling your
|
83
|
|
- script or globally in .bashrc)
|
84
|
|
-
|
85
|
|
-
|
86
|
|
-Principles
|
87
|
|
-----------
|
88
|
|
-
|
89
|
|
-
|
90
|
|
-### Be smart but honest ###
|
91
|
|
-
|
92
|
|
-If you can default, default, otherwise be honest = fail.
|
93
|
|
-
|
94
|
|
-
|
95
|
|
-### Don't talk unless asked ###
|
96
|
|
-
|
97
|
|
-Echo to stdout only if purpose of your script/function **is** to print
|
98
|
|
-**that** text. Otherwise use `think()` instead.
|
99
|
|
-
|
100
|
|
-If you want to make your script "user-friendly" (like babbling about
|
101
|
|
-what it's doing), consider setting `SHELLFU_VERBOSE` to true in header of
|
102
|
|
-your script (and implementing `-q|--quiet` to tun it off).
|
103
|
|
-
|
104
|
|
-
|
105
|
|
-### Stop commenting ###
|
106
|
|
-
|
107
|
|
-Don't use comments if you can make code readable enough.
|
108
|
|
-
|
109
|
|
-Comments are good to explain special cases (like if something you can't
|
110
|
|
-fix is broken so you had to work around and now you know your code is
|
111
|
|
-stupid + ineffective but have to advise colleagues against fixing it).
|
112
|
|
-Sometimes they can be used for TODOs or for FIXMEs. Or if you really
|
113
|
|
-really tried hard but failed to write something in a readable manner
|
114
|
|
-(that's actually a FIXME).
|
115
|
|
-
|
116
|
|
-But people use them also to "title" logical clusters of code (that don't
|
117
|
|
-make sense to separate to functions). Consider using `think` for that.
|
118
|
|
-
|
119
|
|
-
|
120
|
|
-### Go far to make code readable ###
|
121
|
|
-
|
122
|
|
-Often if you can't think of a way to make the code nice, you might have
|
123
|
|
-other problem: your code is too complicated. Note that refactoring
|
124
|
|
-few lines away to a function call or using better (or *some*) naming
|
125
|
|
-convention can be a great help.
|