MCPcopy Create free account
hub / github.com/caarlos0/tasktimer / newToJSONCmd

Function newToJSONCmd

internal/cmd/tojson.go:14–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12}
13
14func newToJSONCmd() *toJSONCmd {
15 cmd := &cobra.Command{
16 Use: "to-json",
17 Short: "Exports the database as JSON",
18 Args: cobra.MaximumNArgs(1),
19 RunE: func(cmd *cobra.Command, args []string) error {
20 project := cmd.Parent().Flag("project").Value.String()
21 db, f, err := setup(project)
22 if err != nil {
23 return err
24 }
25 defer db.Close()
26 defer f.Close()
27
28 if len(args) > 0 {
29 f, err := os.OpenFile(args[0], os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0o666)
30 if err != nil {
31 return err
32 }
33 defer f.Close()
34 return ui.WriteProjectJSON(db, project, f)
35 }
36
37 return ui.WriteProjectJSON(db, project, os.Stdout)
38 },
39 }
40
41 return &toJSONCmd{cmd: cmd}
42}

Callers 2

newEditCmdFunction · 0.85
newRootCmdFunction · 0.85

Calls 2

WriteProjectJSONFunction · 0.92
setupFunction · 0.85

Tested by

no test coverage detected