Skip to content

Commit 294d37c

Browse files
committed
feat(errors): add error message when no command was provided
1 parent 2f7e0e1 commit 294d37c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cmd/duration/duration.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"time"
99
)
1010

11+
// Pads an integer with zeroes to the left
12+
// i.e 01
1113
func padTimePart(timePart int) string {
1214
return fmt.Sprintf("%02d", timePart)
1315
}
@@ -27,6 +29,7 @@ func getHours(time time.Duration) string {
2729
return padTimePart(hours)
2830
}
2931

32+
// Prints the duration how long a command is already running
3033
func printDuration() {
3134
fmt.Printf("command running since: %s:%s:%s", getHours(0), getMinutes(0), getSeconds(0))
3235
start := time.Now()
@@ -44,6 +47,11 @@ func printCmdOutput(output string) {
4447
}
4548

4649
func main() {
50+
if len(os.Args) < 2 {
51+
fmt.Fprintln(os.Stderr, "ERROR: You need to provide a command to execute")
52+
os.Exit(1)
53+
}
54+
4755
program := strings.Join(os.Args[1:2], "")
4856
args := strings.Join(os.Args[2:], " ")
4957

0 commit comments

Comments
 (0)