-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_examples.sh
More file actions
47 lines (43 loc) · 1.06 KB
/
fix_examples.sh
File metadata and controls
47 lines (43 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Script to fix godoc examples to use gotime. prefix for better user-friendliness
# List of function patterns to fix
FUNCTIONS=(
"MonthsBetween"
"DaysBetween"
"WeeksBetween"
"DurationInWords"
"IsValidAge"
"IsLeapYear"
"DaysInMonth"
"DaysInYear"
"DaysInQuarter"
"NewDate"
"NewTime"
"ReplaceDate"
"ReplaceTime"
"QuarterStart"
"QuarterEnd"
"LastQuarter"
"NextQuarter"
"Quarters"
"QuarterOfYear"
"IsBetween"
"IsBetweenDates"
"IsWeekdayPresentInRange"
"CountWeekdaysInRange"
"Hours"
"Minutes"
"Seconds"
"Earliest"
"TruncateTime"
"WorkDay"
"PrevWorkDay"
"NetWorkDays"
)
# Find and replace function calls in godoc examples
for func in "${FUNCTIONS[@]}"; do
echo "Fixing $func examples..."
# Use sed to replace naked function calls with gotime. prefix in example comments
sed -i "s|//\([[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*:=\)[[:space:]]*$func(|//\1 gotime.$func(|g" *.go
done
echo "Fixed godoc examples to use gotime. prefix"