1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package g
6
7import (
8 "fmt"
9
10 "git.secluded.site/np/cmd/shared"
11 "github.com/spf13/cobra"
12)
13
14var GCmd = &cobra.Command{
15 Use: "g",
16 Short: "Goal commands",
17 Long: `Manage the session goal`,
18 RunE: runShowGoal,
19}
20
21func runShowGoal(cmd *cobra.Command, _ []string) error {
22 env, err := shared.Environment(cmd)
23 if err != nil {
24 return err
25 }
26
27 sessionDoc, found, err := shared.ActiveSession(cmd, env)
28 if err != nil {
29 return err
30 }
31 if !found {
32 return nil
33 }
34
35 state, err := shared.PrintPlan(cmd, env, sessionDoc.SID)
36 if err != nil {
37 return err
38 }
39
40 if state.Goal == nil {
41 fmt.Fprintln(cmd.OutOrStdout(), "")
42 fmt.Fprintln(cmd.OutOrStdout(), "Set the goal with `np g s -t \"goal title\" -d \"goal description\"` to begin.")
43 }
44 return nil
45}