Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package cmd

// CLI holds all parsed command-line flags and positional arguments.
type CLI struct {
// operations

// Page holds the positional arguments (page names to look up).
Page []string

// Update requests a cache update.
Update bool

// List requests listing pages for the current platform.
List bool

// ListAll requests listing all pages across all platforms.
ListAll bool

// Search requests a keyword search across pages.
Search string

// ListPlatforms requests listing available platforms.
ListPlatforms bool

// ListLanguages requests listing installed languages.
ListLanguages bool

// Info requests showing cache information.
Info bool

// Render requests rendering a local markdown file.
Render string

// CleanCache requests interactively cleaning the cache.
CleanCache bool

// GenConfig requests printing the default configuration.
GenConfig bool

// ConfigPath requests printing the config file path.
ConfigPath bool

// ShowVersion requests printing the version string.
ShowVersion bool

// ShowHelp requests printing the help text.
ShowHelp bool

// Options

// Platform overrides the platform used for page lookup.
Platform string

// Languages overrides the language list.
Languages []string

// ShortOptions requests displaying short option forms.
ShortOptions bool

// LongOptions requests displaying long option forms.
LongOptions bool

// Edit requests displaying a GitHub edit link.
Edit bool

// Offline suppresses automatic cache updates.
Offline bool

// Compact strips empty lines from output.
Compact bool

// Raw prints pages in raw markdown.
Raw bool

// Quiet suppresses informational and warning messages.
Quiet bool

// Verbose controls the verbosity level (0–2).
Verbose uint8

// Color controls when to enable color output: auto, always, never.
Color string

// Config specifies an alternative config file path.
Config string
}
31 changes: 31 additions & 0 deletions cmd/count_value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import "fmt"

// countValue implements flag.Value for a counter.
//
// Each occurrence of the associated flag increments the counter by one,
// allowing flags such as:
//
// --verbose
// --verbose --verbose
//
// to be represented as increasing verbosity levels.
type countValue struct {
count *uint8
}

// String returns the current counter value as a string.
func (v *countValue) String() string {
if v.count == nil {
return "0"
}

return fmt.Sprintf("%d", *v.count)
}

// Set increments the counter each time the flag is encountered.
func (v *countValue) Set(string) error {
*v.count++
return nil
}
30 changes: 30 additions & 0 deletions cmd/list_values.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import "strings"

// stringListValue implements flag.
// Value for a string slice.
// It supports both repeated flags (-L de -L pl)
// and comma-separated values (-L de,pl).
type stringListValue struct {
values *[]string
}

// String returns the comma-separated representation of the value.
func (v *stringListValue) String() string {
if v.values == nil {
return ""
}
return strings.Join(*v.values, ",")
}

// Set appends one or more comma-separated values to the slice
func (v *stringListValue) Set(s string) error {
for part := range strings.SplitSeq(s, ",") {
part = strings.TrimSpace(part)
if part != "" {
*v.values = append(*v.values, part)
}
}
return nil
}
Loading
Loading