Skip to content

Commit 0e3a232

Browse files
committed
transform all golang files to lf
1 parent 2316f28 commit 0e3a232

29 files changed

+2310
-2310
lines changed

internal/config/options.go

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
package config
2-
3-
import (
4-
"flag"
5-
"strings"
6-
)
7-
8-
// Options represents the global configuration options
9-
type Options struct {
10-
// AllowedContexts is a list of k8s contexts that users are allowed to access
11-
// If empty, all contexts are allowed
12-
AllowedContexts []string
13-
}
14-
15-
// GlobalOptions contains the parsed command line options
16-
var GlobalOptions = &Options{}
17-
18-
// ParseFlags parses the command line flags
19-
func ParseFlags() bool {
20-
var allowedContextsStr string
21-
flag.StringVar(&allowedContextsStr, "allowed-contexts", "", "Comma-separated list of allowed k8s contexts. If empty, all contexts are allowed")
22-
23-
// Add other flags here
24-
25-
// Parse the flags
26-
flag.Parse()
27-
28-
// Check if the flag is --version, version, help or --help
29-
// If so, we don't need to continue processing
30-
if len(flag.Args()) > 0 {
31-
arg := flag.Args()[0]
32-
if arg == "--version" || arg == "version" || arg == "help" || arg == "--help" {
33-
return false
34-
}
35-
}
36-
37-
// Process allowed contexts
38-
if allowedContextsStr != "" {
39-
GlobalOptions.AllowedContexts = strings.Split(allowedContextsStr, ",")
40-
for i, ctx := range GlobalOptions.AllowedContexts {
41-
GlobalOptions.AllowedContexts[i] = strings.TrimSpace(ctx)
42-
}
43-
}
44-
45-
return true
46-
}
47-
48-
// IsContextAllowed checks if a context is allowed based on the configuration
49-
func IsContextAllowed(contextName string) bool {
50-
// If the allowed contexts list is empty, all contexts are allowed
51-
if len(GlobalOptions.AllowedContexts) == 0 {
52-
return true
53-
}
54-
55-
for _, allowed := range GlobalOptions.AllowedContexts {
56-
if allowed == contextName {
57-
return true
58-
}
59-
}
60-
61-
return false
1+
package config
2+
3+
import (
4+
"flag"
5+
"strings"
6+
)
7+
8+
// Options represents the global configuration options
9+
type Options struct {
10+
// AllowedContexts is a list of k8s contexts that users are allowed to access
11+
// If empty, all contexts are allowed
12+
AllowedContexts []string
13+
}
14+
15+
// GlobalOptions contains the parsed command line options
16+
var GlobalOptions = &Options{}
17+
18+
// ParseFlags parses the command line flags
19+
func ParseFlags() bool {
20+
var allowedContextsStr string
21+
flag.StringVar(&allowedContextsStr, "allowed-contexts", "", "Comma-separated list of allowed k8s contexts. If empty, all contexts are allowed")
22+
23+
// Add other flags here
24+
25+
// Parse the flags
26+
flag.Parse()
27+
28+
// Check if the flag is --version, version, help or --help
29+
// If so, we don't need to continue processing
30+
if len(flag.Args()) > 0 {
31+
arg := flag.Args()[0]
32+
if arg == "--version" || arg == "version" || arg == "help" || arg == "--help" {
33+
return false
34+
}
35+
}
36+
37+
// Process allowed contexts
38+
if allowedContextsStr != "" {
39+
GlobalOptions.AllowedContexts = strings.Split(allowedContextsStr, ",")
40+
for i, ctx := range GlobalOptions.AllowedContexts {
41+
GlobalOptions.AllowedContexts[i] = strings.TrimSpace(ctx)
42+
}
43+
}
44+
45+
return true
46+
}
47+
48+
// IsContextAllowed checks if a context is allowed based on the configuration
49+
func IsContextAllowed(contextName string) bool {
50+
// If the allowed contexts list is empty, all contexts are allowed
51+
if len(GlobalOptions.AllowedContexts) == 0 {
52+
return true
53+
}
54+
55+
for _, allowed := range GlobalOptions.AllowedContexts {
56+
if allowed == contextName {
57+
return true
58+
}
59+
}
60+
61+
return false
6262
}

internal/config/options_test.go

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
package config
2-
3-
import (
4-
"testing"
5-
)
6-
7-
func TestIsContextAllowed(t *testing.T) {
8-
// Reset the global options between tests
9-
defer func() {
10-
GlobalOptions = &Options{}
11-
}()
12-
13-
tests := []struct {
14-
name string
15-
allowedContexts []string
16-
contextName string
17-
expected bool
18-
}{
19-
{
20-
name: "all contexts allowed when no restrictions",
21-
allowedContexts: []string{},
22-
contextName: "any-context",
23-
expected: true,
24-
},
25-
{
26-
name: "context explicitly allowed",
27-
allowedContexts: []string{"context-1", "context-2"},
28-
contextName: "context-1",
29-
expected: true,
30-
},
31-
{
32-
name: "context not allowed",
33-
allowedContexts: []string{"context-1", "context-2"},
34-
contextName: "context-3",
35-
expected: false,
36-
},
37-
}
38-
39-
for _, tt := range tests {
40-
t.Run(tt.name, func(t *testing.T) {
41-
// Setup
42-
GlobalOptions.AllowedContexts = tt.allowedContexts
43-
44-
// Test
45-
result := IsContextAllowed(tt.contextName)
46-
47-
// Verify
48-
if result != tt.expected {
49-
t.Errorf("IsContextAllowed(%q) = %v, want %v",
50-
tt.contextName, result, tt.expected)
51-
}
52-
})
53-
}
1+
package config
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestIsContextAllowed(t *testing.T) {
8+
// Reset the global options between tests
9+
defer func() {
10+
GlobalOptions = &Options{}
11+
}()
12+
13+
tests := []struct {
14+
name string
15+
allowedContexts []string
16+
contextName string
17+
expected bool
18+
}{
19+
{
20+
name: "all contexts allowed when no restrictions",
21+
allowedContexts: []string{},
22+
contextName: "any-context",
23+
expected: true,
24+
},
25+
{
26+
name: "context explicitly allowed",
27+
allowedContexts: []string{"context-1", "context-2"},
28+
contextName: "context-1",
29+
expected: true,
30+
},
31+
{
32+
name: "context not allowed",
33+
allowedContexts: []string{"context-1", "context-2"},
34+
contextName: "context-3",
35+
expected: false,
36+
},
37+
}
38+
39+
for _, tt := range tests {
40+
t.Run(tt.name, func(t *testing.T) {
41+
// Setup
42+
GlobalOptions.AllowedContexts = tt.allowedContexts
43+
44+
// Test
45+
result := IsContextAllowed(tt.contextName)
46+
47+
// Verify
48+
if result != tt.expected {
49+
t.Errorf("IsContextAllowed(%q) = %v, want %v",
50+
tt.contextName, result, tt.expected)
51+
}
52+
})
53+
}
5454
}

internal/content/json.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
package content
2-
3-
import (
4-
"encoding/json"
5-
6-
"github.com/strowk/foxy-contexts/pkg/mcp"
7-
)
8-
9-
func NewJsonContent(v any) (mcp.TextContent, error) {
10-
contents, err := json.Marshal(v)
11-
if err != nil {
12-
return mcp.TextContent{}, err
13-
}
14-
return mcp.TextContent{
15-
Type: "text",
16-
Text: string(contents),
17-
}, nil
18-
}
1+
package content
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/strowk/foxy-contexts/pkg/mcp"
7+
)
8+
9+
func NewJsonContent(v any) (mcp.TextContent, error) {
10+
contents, err := json.Marshal(v)
11+
if err != nil {
12+
return mcp.TextContent{}, err
13+
}
14+
return mcp.TextContent{
15+
Type: "text",
16+
Text: string(contents),
17+
}, nil
18+
}

0 commit comments

Comments
 (0)