-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoutfile.go
More file actions
73 lines (63 loc) · 1.72 KB
/
Copy pathoutfile.go
File metadata and controls
73 lines (63 loc) · 1.72 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-FileCopyrightText: Copyright 2025 Carabiner Systems, Inc
// SPDX-License-Identifier: Apache-2.0
package command
import (
"fmt"
"io"
"os"
"github.com/spf13/cobra"
)
var _ OptionsSet = &OutputFile{}
// OutputFile provides output file configuration for Carabiner applications.
//
// Deprecated: Use github.com/carabiner-dev/command/output.Options instead.
type OutputFile struct {
config *OptionsSetConfig
OutputPath string
}
// Config returns the flag configuration for output options.
//
// Deprecated: Use github.com/carabiner-dev/command/output.Options instead.
func (oo *OutputFile) Config() *OptionsSetConfig {
if oo.config == nil {
oo.config = &OptionsSetConfig{
Flags: map[string]FlagConfig{
"output": {
Short: "o",
Long: "output",
Help: "file path to write the output (defaults to STDOUT)",
},
},
}
}
return oo.config
}
// AddFlags adds the options flags to a command.
//
// Deprecated: Use github.com/carabiner-dev/command/output.Options instead.
func (oo *OutputFile) AddFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVarP(
&oo.OutputPath, oo.config.LongFlag("output"),
oo.config.ShortFlag("output"), "",
oo.config.HelpText("output"),
)
}
// Validate checks the output options.
//
// Deprecated: Use github.com/carabiner-dev/command/output.Options instead.
func (oo *OutputFile) Validate() error {
return nil
}
// GetWriter returns a writer for the output.
//
// Deprecated: Use github.com/carabiner-dev/command/output.Options instead.
func (oo *OutputFile) GetWriter() (io.Writer, error) {
if oo.OutputPath == "" {
return os.Stdout, nil
}
f, err := os.Create(oo.OutputPath)
if err != nil {
return nil, fmt.Errorf("opening output file: %w", err)
}
return f, nil
}