-
Notifications
You must be signed in to change notification settings - Fork 2
/
away.go
53 lines (44 loc) · 1.49 KB
/
away.go
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
48
49
50
51
52
53
/*
Copyright (c) Yankee Maharjan 2022. All rights reserved.
Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/yankeexe/slack-status-cli/internal/client"
"github.com/yankeexe/slack-status-cli/internal/utils"
)
// awayCmd represents the away command
var awayCmd = &cobra.Command{
Use: "away",
Short: "Set your status to away with DND",
Long: `Set your status to away with DND
Valid durations for --dnd flag includes:
- minutes, hours or days.
DEFAULTS to minutes
NOTE: use single or double quotes around the value if contains space.
OPTIONS for the duration:
minute: m, min, mins :: Example: "10 m", "10 mins", 10minute, "10 minutes"
hour: h, hr, hour, hours :: Example: "1 h", 1hr, "1 hour", "1 hours"
day: d, day, days :: Example: 2d, "2 day", 2days
`,
Run: func(cmd *cobra.Command, args []string) {
client, err := client.GetClient()
utils.CheckIfError(err)
client.SetUserPresence("away")
dnd, err := cmd.Flags().GetString("dnd")
utils.CheckIfError(err)
if len(dnd) != 0 && dnd != "0" {
parsed := utils.ParseDuration(dnd)
_, err := client.SetSnooze(parsed.AbsolutePeriod)
utils.CheckIfError(err)
fmt.Printf("🚫 DND enabled for %v\n", parsed.UserDefinedDuration)
}
fmt.Println("✅ Status set to away!")
},
}
func init() {
rootCmd.AddCommand(awayCmd)
awayCmd.Flags().String("dnd", "", "set do not disturb mode with user-defined duration")
}