config

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdName = "leetgo"

	ProjectConfigFilename = CmdName + ".yaml"

	CodeBeginMarker    = "@lc code=begin"
	CodeEndMarker      = "@lc code=end"
	GoTestUtilsModPath = "github.com/j178/leetgo/testutils/go"
	ProjectURL         = "https://github.com/j178/leetgo"
)
View Source
const (
	LeetCodeCN LeetcodeSite = "https://leetcode.cn"
	LeetCodeUS LeetcodeSite = "https://leetcode.com"
	ZH         Language     = "zh"
	EN         Language     = "en"
)

Variables

View Source
var (
	Debug = os.Getenv("DEBUG") == "1"
)

Functions

func Decrypt

func Decrypt(in string) (string, error)

func Encrypt

func Encrypt(in string) (string, error)

func Load

func Load(init bool) error

func SaveState

func SaveState(s State)

Types

type BaseLangConfig

type BaseLangConfig struct {
	OutDir           string     `yaml:"out_dir" mapstructure:"out_dir"`
	FilenameTemplate string     `yaml:"filename_template" mapstructure:"filename_template" comment:"Overrides the default code.filename_template"`
	Blocks           []Block    `yaml:"blocks,omitempty" mapstructure:"blocks" comment:"Replace some blocks of the generated code"`
	Modifiers        []Modifier `yaml:"modifiers,omitempty" mapstructure:"modifiers" comment:"Functions that modify the generated code"`
}

type Block added in v0.1.6

type Block struct {
	Name     string `yaml:"name" mapstructure:"name"`
	Template string `yaml:"template" mapstructure:"template"`
}

type CodeConfig

type CodeConfig struct {
	Lang             string         `` /* 154-byte string literal not displayed */
	FilenameTemplate string         `` /* 296-byte string literal not displayed */
	Blocks           []Block        `yaml:"blocks,omitempty" mapstructure:"blocks" comment:"Replace some blocks of the generated code"`
	Modifiers        []Modifier     `yaml:"modifiers,omitempty" mapstructure:"modifiers" comment:"Functions that modify the generated code"`
	Go               GoConfig       `yaml:"go" mapstructure:"go"`
	Python           BaseLangConfig `yaml:"python3" mapstructure:"python3"`
	Cpp              BaseLangConfig `yaml:"cpp" mapstructure:"cpp"`
	Java             BaseLangConfig `yaml:"java" mapstructure:"java"`
	Rust             BaseLangConfig `yaml:"rust" mapstructure:"rust"`
}

type Config

type Config struct {
	Author   string         `yaml:"author" mapstructure:"author" comment:"Your name"`
	Language Language       `yaml:"language" mapstructure:"language" comment:"Language of the question description: zh or en"`
	Code     CodeConfig     `yaml:"code" mapstructure:"code" comment:"Code configuration"`
	LeetCode LeetCodeConfig `yaml:"leetcode" mapstructure:"leetcode" comment:"LeetCode configuration"`
	Contest  ContestConfig  `yaml:"contest" mapstructure:"contest"`
	Editor   Editor         `yaml:"editor" mapstructure:"editor" comment:"The editor to open generated files"`
	// contains filtered or unexported fields
}

func Default

func Default() *Config

func Get

func Get() *Config

func (*Config) CacheDir added in v0.2.1

func (c *Config) CacheDir() string

func (*Config) ConfigDir

func (c *Config) ConfigDir() string

func (*Config) GlobalConfigFile

func (c *Config) GlobalConfigFile() string

func (*Config) ProjectConfigFile

func (c *Config) ProjectConfigFile() string

func (*Config) ProjectRoot

func (c *Config) ProjectRoot() string

func (*Config) QuestionCacheFile added in v0.2.1

func (c *Config) QuestionCacheFile(ext string) string

func (*Config) StateFile

func (c *Config) StateFile() string

func (*Config) Write

func (c *Config) Write(w io.Writer, withComments bool) error

type ContestConfig

type ContestConfig struct {
	OutDir           string `yaml:"out_dir" mapstructure:"out_dir" comment:"Base dir to put generated contest questions"`
	FilenameTemplate string `yaml:"filename_template" mapstructure:"filename_template" comment:"Template to generate filename of the question"`
	OpenInBrowser    bool   `yaml:"open_in_browser" mapstructure:"open_in_browser" comment:"Open the contest page in browser after generating"`
}

type Credentials

type Credentials struct {
	From      string `yaml:"from" mapstructure:"from" comment:"How to provide credentials: browser, cookies, password or none"`
	Session   string `yaml:"session" mapstructure:"session" comment:"LeetCode cookie: LEETCODE_SESSION"`
	CsrfToken string `yaml:"csrftoken" mapstructure:"csrftoken" comment:"LeetCode cookie: csrftoken"`
	Username  string `yaml:"username" mapstructure:"username" comment:"LeetCode username"`
	Password  string `yaml:"password" mapstructure:"password" comment:"Encrypted LeetCode password"`
}

type Editor

type Editor struct {
	Use     string   `` /* 155-byte string literal not displayed */
	Command string   `yaml:"command" mapstructure:"command" comment:"Custom command to open files"`
	Args    []string `yaml:"args" mapstructure:"args" comment:"Arguments to the command"`
}

type GoConfig

type GoConfig struct {
	BaseLangConfig `yaml:",inline" mapstructure:",squash"`
	GoModPath      string `yaml:"go_mod_path" mapstructure:"go_mod_path" comment:"Go module path for the generated code"`
}

type Language

type Language string

type LastQuestion

type LastQuestion struct {
	FrontendID string `json:"frontend_id"`
	Slug       string `json:"slug"`
	Gen        string `json:"gen"`
}

type LeetCodeConfig

type LeetCodeConfig struct {
	Site        LeetcodeSite `yaml:"site" mapstructure:"site" comment:"LeetCode site, https://leetcode.com or https://leetcode.cn"`
	Credentials Credentials  `yaml:"credentials" mapstructure:"credentials" comment:"Credentials to access LeetCode"`
}

type LeetcodeSite

type LeetcodeSite string

type Modifier added in v0.1.6

type Modifier struct {
	Name   string `yaml:"name" mapstructure:"name"`
	Script string `yaml:"script,omitempty" mapstructure:"script"`
}

type State

type State struct {
	LastQuestion LastQuestion `json:"last_question"`
	LastContest  string       `json:"last_contest"`
}

func LoadState

func LoadState() State

type States

type States map[string]State

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL