-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Environment Variables | ||
|
||
| Name | Usage | Default | | ||
| --- | --- | --- | | ||
| `CSS_ACTION_TYPES` | SponsorBlock action types to handle. Shorter segments that overlap with content can be muted instead of skipped. | `skip,mute` | | ||
| `CSS_CATEGORIES` | Comma-separated list of SponsorBlock categories to skip | `sponsor` | | ||
| `CSS_DEVICES` | Comma-separated list of device addresses. This will disable discovery and is not recommended unless discovery fails | ` ` | | ||
| `CSS_DISCOVER_INTERVAL` | Interval to restart the DNS discovery client | `5m0s` | | ||
| `CSS_IGNORE_SEGMENT_DURATION` | Ignores the previous sponsored segment for a set amount of time. Useful if you want to to go back and watch a segment. | `1m0s` | | ||
| `CSS_LOG_FORMAT` | Log format (one of: auto, color, plain, json) | `auto` | | ||
| `CSS_LOG_LEVEL` | Log level (one of: debug, info, warn, error) | `info` | | ||
| `CSS_MUTE_ADS` | Mutes the device while an ad is playing | `true` | | ||
| `CSS_NETWORK_INTERFACE` | Network interface to use for multicast dns discovery. (default all interfaces) | ` ` | | ||
| `CSS_PAUSED_INTERVAL` | Interval to scan paused devices | `1m0s` | | ||
| `CSS_PLAYING_INTERVAL` | Interval to scan playing devices | `500ms` | | ||
| `CSS_SKIP_DELAY` | Delay skipping the start of a segment | `0s` | | ||
| `CSS_SKIP_SPONSORS` | Skip sponsored segments with SponsorBlock | `true` | | ||
| `CSS_YOUTUBE_API_KEY` | YouTube API key for fallback video identification (required on some Chromecast devices). | ` ` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,101 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"io" | ||
"log/slog" | ||
"os" | ||
"path/filepath" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/gabe565/castsponsorskip/cmd" | ||
"github.com/gabe565/castsponsorskip/internal/config" | ||
"github.com/gabe565/castsponsorskip/internal/config/names" | ||
"github.com/jedib0t/go-pretty/v6/table" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/cobra/doc" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func main() { | ||
var err error | ||
output := "./docs" | ||
|
||
err = os.RemoveAll(output) | ||
if err != nil { | ||
log.Fatal(fmt.Errorf("failed to remove existing dia: %w", err)) | ||
if err := os.RemoveAll(output); err != nil { | ||
slog.Error("failed to remove existing dir", "error", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = os.MkdirAll(output, 0o755) | ||
if err != nil { | ||
log.Fatal(fmt.Errorf("failed to mkdir: %w", err)) | ||
if err := os.MkdirAll(output, 0o755); err != nil { | ||
slog.Error("failed to mkdir", "error", err) | ||
os.Exit(1) | ||
} | ||
|
||
root := cmd.New(cmd.WithVersion("beta")) | ||
|
||
if err := errors.Join( | ||
generateFlagDoc(root, output), | ||
generateEnvDoc(root, filepath.Join(output, "envs.md")), | ||
); err != nil { | ||
slog.Error(err.Error()) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func generateFlagDoc(cmd *cobra.Command, output string) error { | ||
if err := doc.GenMarkdownTree(cmd, output); err != nil { | ||
return fmt.Errorf("failed to generate markdown: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
rootCmd := cmd.New(cmd.WithVersion("beta")) | ||
func generateEnvDoc(cmd *cobra.Command, output string) error { | ||
excludeNames := []string{"completion", names.FlagConfig, "help", "version"} | ||
var rows []table.Row | ||
cmd.Flags().VisitAll(func(flag *pflag.Flag) { | ||
if slices.Contains(excludeNames, flag.Name) { | ||
return | ||
} | ||
|
||
err = doc.GenMarkdownTree(rootCmd, output) | ||
var value string | ||
switch fv := flag.Value.(type) { | ||
case pflag.SliceValue: | ||
value = strings.Join(flag.Value.(pflag.SliceValue).GetSlice(), ",") | ||
default: | ||
value = fv.String() | ||
} | ||
if value == "" { | ||
value = " " | ||
} | ||
|
||
rows = append(rows, table.Row{ | ||
"`" + config.EnvPrefix + strings.ReplaceAll(strings.ToUpper(flag.Name), "-", "_") + "`", | ||
flag.Usage, | ||
"`" + value + "`", | ||
}) | ||
}) | ||
t := table.NewWriter() | ||
t.AppendHeader(table.Row{"Name", "Usage", "Default"}) | ||
t.AppendRows(rows) | ||
|
||
var buf strings.Builder | ||
buf.WriteString("# Environment Variables\n\n") | ||
buf.WriteString(t.RenderMarkdown()) | ||
|
||
f, err := os.Create(output) | ||
if err != nil { | ||
log.Fatal(fmt.Errorf("failed to generate markdown: %w", err)) | ||
return fmt.Errorf("failed to create env file: %w", err) | ||
} | ||
defer f.Close() | ||
|
||
if _, err := io.WriteString(f, buf.String()); err != nil { | ||
return fmt.Errorf("failed to write to env file: %w", err) | ||
} | ||
|
||
if err := f.Close(); err != nil { | ||
return fmt.Errorf("failed to close env file: %w", err) | ||
} | ||
|
||
return nil | ||
} |