mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-10 23:57:43 +02:00
Add UserConfig jsonschema generation script
This commit is contained in:
parent
df5b3693d6
commit
1a035db4c8
@ -53,7 +53,7 @@ func (self *ConfigCommands) GetPager(width int) string {
|
|||||||
"columnWidth": strconv.Itoa(width/2 - 6),
|
"columnWidth": strconv.Itoa(width/2 - 6),
|
||||||
}
|
}
|
||||||
|
|
||||||
pagerTemplate := self.UserConfig.Git.Paging.Pager
|
pagerTemplate := string(self.UserConfig.Git.Paging.Pager)
|
||||||
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/karimkhaleel/jsonschema"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserConfig struct {
|
type UserConfig struct {
|
||||||
@ -25,7 +27,7 @@ type UserConfig struct {
|
|||||||
// Lazygit sets this to true upon first runninng the program so that you don't see introductory popups every time you open the program.
|
// Lazygit sets this to true upon first runninng the program so that you don't see introductory popups every time you open the program.
|
||||||
DisableStartupPopups bool `yaml:"disableStartupPopups"`
|
DisableStartupPopups bool `yaml:"disableStartupPopups"`
|
||||||
// User-configured commands that can be invoked from within Lazygit
|
// User-configured commands that can be invoked from within Lazygit
|
||||||
CustomCommands []CustomCommand `yaml:"customCommands"`
|
CustomCommands []CustomCommand `yaml:"customCommands" jsonschema:"uniqueItems=true"`
|
||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-pull-request-urls
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-pull-request-urls
|
||||||
Services map[string]string `yaml:"services"`
|
Services map[string]string `yaml:"services"`
|
||||||
// What to do when opening Lazygit outside of a git repo.
|
// What to do when opening Lazygit outside of a git repo.
|
||||||
@ -33,7 +35,7 @@ type UserConfig struct {
|
|||||||
// - 'create': initialize a new repo
|
// - 'create': initialize a new repo
|
||||||
// - 'skip': open most recent repo
|
// - 'skip': open most recent repo
|
||||||
// - 'quit': exit Lazygit
|
// - 'quit': exit Lazygit
|
||||||
NotARepository string `yaml:"notARepository"`
|
NotARepository string `yaml:"notARepository" jsonschema:"enum=prompt,enum=create,enum=skip,enum=quit"`
|
||||||
// If true, display a confirmation when subprocess terminates. This allows you to view the output of the subprocess before returning to Lazygit.
|
// If true, display a confirmation when subprocess terminates. This allows you to view the output of the subprocess before returning to Lazygit.
|
||||||
PromptToReturnFromSubprocess bool `yaml:"promptToReturnFromSubprocess"`
|
PromptToReturnFromSubprocess bool `yaml:"promptToReturnFromSubprocess"`
|
||||||
}
|
}
|
||||||
@ -41,10 +43,10 @@ type UserConfig struct {
|
|||||||
type RefresherConfig struct {
|
type RefresherConfig struct {
|
||||||
// File/submodule refresh interval in seconds.
|
// File/submodule refresh interval in seconds.
|
||||||
// Auto-refresh can be disabled via option 'git.autoRefresh'.
|
// Auto-refresh can be disabled via option 'git.autoRefresh'.
|
||||||
RefreshInterval int `yaml:"refreshInterval"`
|
RefreshInterval int `yaml:"refreshInterval" jsonschema:"minimum=0"`
|
||||||
// Re-fetch interval in seconds.
|
// Re-fetch interval in seconds.
|
||||||
// Auto-fetch can be disabled via option 'git.autoFetch'.
|
// Auto-fetch can be disabled via option 'git.autoFetch'.
|
||||||
FetchInterval int `yaml:"fetchInterval"`
|
FetchInterval int `yaml:"fetchInterval" jsonschema:"minimum=0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GuiConfig struct {
|
type GuiConfig struct {
|
||||||
@ -53,7 +55,7 @@ type GuiConfig struct {
|
|||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-branch-color
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-branch-color
|
||||||
BranchColors map[string]string `yaml:"branchColors"`
|
BranchColors map[string]string `yaml:"branchColors"`
|
||||||
// The number of lines you scroll by when scrolling the main window
|
// The number of lines you scroll by when scrolling the main window
|
||||||
ScrollHeight int `yaml:"scrollHeight"`
|
ScrollHeight int `yaml:"scrollHeight" jsonschema:"minimum=1"`
|
||||||
// If true, allow scrolling past the bottom of the content in the main window
|
// If true, allow scrolling past the bottom of the content in the main window
|
||||||
ScrollPastBottom bool `yaml:"scrollPastBottom"`
|
ScrollPastBottom bool `yaml:"scrollPastBottom"`
|
||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#scroll-off-margin
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#scroll-off-margin
|
||||||
@ -73,7 +75,7 @@ type GuiConfig struct {
|
|||||||
SkipRewordInEditorWarning bool `yaml:"skipRewordInEditorWarning"`
|
SkipRewordInEditorWarning bool `yaml:"skipRewordInEditorWarning"`
|
||||||
// Fraction of the total screen width to use for the left side section. You may want to pick a small number (e.g. 0.2) if you're using a narrow screen, so that you can see more of the main section.
|
// Fraction of the total screen width to use for the left side section. You may want to pick a small number (e.g. 0.2) if you're using a narrow screen, so that you can see more of the main section.
|
||||||
// Number from 0 to 1.0.
|
// Number from 0 to 1.0.
|
||||||
SidePanelWidth float64 `yaml:"sidePanelWidth"`
|
SidePanelWidth float64 `yaml:"sidePanelWidth" jsonschema:"maximum=1,minimum=0"`
|
||||||
// If true, increase the height of the focused side window; creating an accordion effect.
|
// If true, increase the height of the focused side window; creating an accordion effect.
|
||||||
ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"`
|
ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"`
|
||||||
// Sometimes the main window is split in two (e.g. when the selected file has both staged and unstaged changes). This setting controls how the two sections are split.
|
// Sometimes the main window is split in two (e.g. when the selected file has both staged and unstaged changes). This setting controls how the two sections are split.
|
||||||
@ -81,9 +83,9 @@ type GuiConfig struct {
|
|||||||
// - 'horizontal': split the window horizontally
|
// - 'horizontal': split the window horizontally
|
||||||
// - 'vertical': split the window vertically
|
// - 'vertical': split the window vertically
|
||||||
// - 'flexible': (default) split the window horizontally if the window is wide enough, otherwise split vertically
|
// - 'flexible': (default) split the window horizontally if the window is wide enough, otherwise split vertically
|
||||||
MainPanelSplitMode string `yaml:"mainPanelSplitMode"`
|
MainPanelSplitMode string `yaml:"mainPanelSplitMode" jsonschema:"enum=horizontal,enum=flexible,enum=vertical"`
|
||||||
// One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
|
// One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
|
||||||
Language string `yaml:"language"`
|
Language string `yaml:"language" jsonschema:"enum=auto,enum=en,enum=zh-TW,enum=zh-CN,enum=pl,enum=nl,enum=ja,enum=ko,enum=ru"`
|
||||||
// Format used when displaying time e.g. commit time.
|
// Format used when displaying time e.g. commit time.
|
||||||
// Uses Go's time format syntax: https://pkg.go.dev/time#Time.Format
|
// Uses Go's time format syntax: https://pkg.go.dev/time#Time.Format
|
||||||
TimeFormat string `yaml:"timeFormat"`
|
TimeFormat string `yaml:"timeFormat"`
|
||||||
@ -113,21 +115,21 @@ type GuiConfig struct {
|
|||||||
// Nerd fonts version to use.
|
// Nerd fonts version to use.
|
||||||
// One of: '2' | '3' | empty string (default)
|
// One of: '2' | '3' | empty string (default)
|
||||||
// If empty, do not show icons.
|
// If empty, do not show icons.
|
||||||
NerdFontsVersion string `yaml:"nerdFontsVersion"`
|
NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum="`
|
||||||
// If true, show commit hashes alongside branch names in the branches view.
|
// If true, show commit hashes alongside branch names in the branches view.
|
||||||
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
|
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
|
||||||
// Height of the command log view
|
// Height of the command log view
|
||||||
CommandLogSize int `yaml:"commandLogSize"`
|
CommandLogSize int `yaml:"commandLogSize" jsonschema:"minimum=0"`
|
||||||
// Whether to split the main window when viewing file changes.
|
// Whether to split the main window when viewing file changes.
|
||||||
// One of: 'auto' | 'always'
|
// One of: 'auto' | 'always'
|
||||||
// If 'auto', only split the main window when a file has both staged and unstaged changes
|
// If 'auto', only split the main window when a file has both staged and unstaged changes
|
||||||
SplitDiff string `yaml:"splitDiff"`
|
SplitDiff string `yaml:"splitDiff" jsonschema:"enum=auto,enum=always"`
|
||||||
// Default size for focused window. Window size can be changed from within Lazygit with '+' and '_' (but this won't change the default).
|
// Default size for focused window. Window size can be changed from within Lazygit with '+' and '_' (but this won't change the default).
|
||||||
// One of: 'normal' (default) | 'half' | 'full'
|
// One of: 'normal' (default) | 'half' | 'full'
|
||||||
WindowSize string `yaml:"windowSize"`
|
WindowSize string `yaml:"windowSize" jsonschema:"enum=normal,enum=half,enum=full"`
|
||||||
// Window border style.
|
// Window border style.
|
||||||
// One of 'rounded' (default) | 'single' | 'double' | 'hidden'
|
// One of 'rounded' (default) | 'single' | 'double' | 'hidden'
|
||||||
Border string `yaml:"border"`
|
Border string `yaml:"border" jsonschema:"enum=single,enum=double,enum=rounded,enum=hidden"`
|
||||||
// If true, show a seriously epic explosion animation when nuking the working tree.
|
// If true, show a seriously epic explosion animation when nuking the working tree.
|
||||||
AnimateExplosion bool `yaml:"animateExplosion"`
|
AnimateExplosion bool `yaml:"animateExplosion"`
|
||||||
// Whether to stack UI components on top of each other.
|
// Whether to stack UI components on top of each other.
|
||||||
@ -137,31 +139,31 @@ type GuiConfig struct {
|
|||||||
|
|
||||||
type ThemeConfig struct {
|
type ThemeConfig struct {
|
||||||
// Border color of focused window
|
// Border color of focused window
|
||||||
ActiveBorderColor []string `yaml:"activeBorderColor"`
|
ActiveBorderColor []string `yaml:"activeBorderColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Border color of non-focused windows
|
// Border color of non-focused windows
|
||||||
InactiveBorderColor []string `yaml:"inactiveBorderColor"`
|
InactiveBorderColor []string `yaml:"inactiveBorderColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Border color of focused window when searching in that window
|
// Border color of focused window when searching in that window
|
||||||
SearchingActiveBorderColor []string `yaml:"searchingActiveBorderColor"`
|
SearchingActiveBorderColor []string `yaml:"searchingActiveBorderColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Color of keybindings help text in the bottom line
|
// Color of keybindings help text in the bottom line
|
||||||
OptionsTextColor []string `yaml:"optionsTextColor"`
|
OptionsTextColor []string `yaml:"optionsTextColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Background color of selected line.
|
// Background color of selected line.
|
||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
|
||||||
SelectedLineBgColor []string `yaml:"selectedLineBgColor"`
|
SelectedLineBgColor []string `yaml:"selectedLineBgColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Background color of selected range
|
// Background color of selected range
|
||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
|
||||||
SelectedRangeBgColor []string `yaml:"selectedRangeBgColor"`
|
SelectedRangeBgColor []string `yaml:"selectedRangeBgColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Foreground color of copied commit
|
// Foreground color of copied commit
|
||||||
CherryPickedCommitFgColor []string `yaml:"cherryPickedCommitFgColor"`
|
CherryPickedCommitFgColor []string `yaml:"cherryPickedCommitFgColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Background color of copied commit
|
// Background color of copied commit
|
||||||
CherryPickedCommitBgColor []string `yaml:"cherryPickedCommitBgColor"`
|
CherryPickedCommitBgColor []string `yaml:"cherryPickedCommitBgColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Foreground color of marked base commit (for rebase)
|
// Foreground color of marked base commit (for rebase)
|
||||||
MarkedBaseCommitFgColor []string `yaml:"markedBaseCommitFgColor"`
|
MarkedBaseCommitFgColor []string `yaml:"markedBaseCommitFgColor"`
|
||||||
// Background color of marked base commit (for rebase)
|
// Background color of marked base commit (for rebase)
|
||||||
MarkedBaseCommitBgColor []string `yaml:"markedBaseCommitBgColor"`
|
MarkedBaseCommitBgColor []string `yaml:"markedBaseCommitBgColor"`
|
||||||
// Color for file with unstaged changes
|
// Color for file with unstaged changes
|
||||||
UnstagedChangesColor []string `yaml:"unstagedChangesColor"`
|
UnstagedChangesColor []string `yaml:"unstagedChangesColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
// Default text color
|
// Default text color
|
||||||
DefaultFgColor []string `yaml:"defaultFgColor"`
|
DefaultFgColor []string `yaml:"defaultFgColor" jsonschema:"minItems=1,uniqueItems=true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitLengthConfig struct {
|
type CommitLengthConfig struct {
|
||||||
@ -177,7 +179,7 @@ type GitConfig struct {
|
|||||||
// Config relating to merging
|
// Config relating to merging
|
||||||
Merging MergingConfig `yaml:"merging"`
|
Merging MergingConfig `yaml:"merging"`
|
||||||
// list of branches that are considered 'main' branches, used when displaying commits
|
// list of branches that are considered 'main' branches, used when displaying commits
|
||||||
MainBranches []string `yaml:"mainBranches"`
|
MainBranches []string `yaml:"mainBranches" jsonschema:"uniqueItems=true"`
|
||||||
// Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'
|
// Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'
|
||||||
SkipHookPrefix string `yaml:"skipHookPrefix"`
|
SkipHookPrefix string `yaml:"skipHookPrefix"`
|
||||||
// If true, periodically fetch from remote
|
// If true, periodically fetch from remote
|
||||||
@ -203,14 +205,24 @@ type GitConfig struct {
|
|||||||
Log LogConfig `yaml:"log"`
|
Log LogConfig `yaml:"log"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PagerType string
|
||||||
|
|
||||||
|
func (PagerType) JSONSchemaExtend(schema *jsonschema.Schema) {
|
||||||
|
schema.Examples = []any{
|
||||||
|
"delta --dark --paging=never",
|
||||||
|
"diff-so-fancy",
|
||||||
|
"ydiff -p cat -s --wrap --width={{columnWidth}}",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type PagingConfig struct {
|
type PagingConfig struct {
|
||||||
// Value of the --color arg in the git diff command. Some pagers want this to be set to 'always' and some want it set to 'never'
|
// Value of the --color arg in the git diff command. Some pagers want this to be set to 'always' and some want it set to 'never'
|
||||||
ColorArg string `yaml:"colorArg"`
|
ColorArg string `yaml:"colorArg" jsonschema:"enum=always,enum=never"`
|
||||||
// e.g.
|
// e.g.
|
||||||
// diff-so-fancy
|
// diff-so-fancy
|
||||||
// delta --dark --paging=never
|
// delta --dark --paging=never
|
||||||
// ydiff -p cat -s --wrap --width={{columnWidth}}
|
// ydiff -p cat -s --wrap --width={{columnWidth}}
|
||||||
Pager string `yaml:"pager"`
|
Pager PagerType `yaml:"pager" jsonschema:"minLength=1"`
|
||||||
// If true, Lazygit will use whatever pager is specified in `$GIT_PAGER`, `$PAGER`, or your *git config*. If the pager ends with something like ` | less` we will strip that part out, because less doesn't play nice with our rendering approach. If the custom pager uses less under the hood, that will also break rendering (hence the `--paging=never` flag for the `delta` pager).
|
// If true, Lazygit will use whatever pager is specified in `$GIT_PAGER`, `$PAGER`, or your *git config*. If the pager ends with something like ` | less` we will strip that part out, because less doesn't play nice with our rendering approach. If the custom pager uses less under the hood, that will also break rendering (hence the `--paging=never` flag for the `delta` pager).
|
||||||
UseConfig bool `yaml:"useConfig"`
|
UseConfig bool `yaml:"useConfig"`
|
||||||
// e.g. 'difft --color=always'
|
// e.g. 'difft --color=always'
|
||||||
@ -227,33 +239,33 @@ type MergingConfig struct {
|
|||||||
// Only applicable to unix users.
|
// Only applicable to unix users.
|
||||||
ManualCommit bool `yaml:"manualCommit"`
|
ManualCommit bool `yaml:"manualCommit"`
|
||||||
// Extra args passed to `git merge`, e.g. --no-ff
|
// Extra args passed to `git merge`, e.g. --no-ff
|
||||||
Args string `yaml:"args"`
|
Args string `yaml:"args" jsonschema:"example=--no-ff"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogConfig struct {
|
type LogConfig struct {
|
||||||
// One of: 'date-order' | 'author-date-order' | 'topo-order'
|
// One of: 'date-order' | 'author-date-order' | 'topo-order | default'
|
||||||
// 'topo-order' makes it easier to read the git log graph, but commits may not
|
// 'topo-order' makes it easier to read the git log graph, but commits may not
|
||||||
// appear chronologically. See https://git-scm.com/docs/
|
// appear chronologically. See https://git-scm.com/docs/
|
||||||
Order string `yaml:"order"`
|
Order string `yaml:"order" jsonschema:"enum=date-order,enum=author-date-order,enum=topo-order,enum=default"`
|
||||||
// This determines whether the git graph is rendered in the commits panel
|
// This determines whether the git graph is rendered in the commits panel
|
||||||
// One of 'always' | 'never' 'when-maximised'
|
// One of 'always' | 'never' | 'when-maximised'
|
||||||
ShowGraph string `yaml:"showGraph"`
|
ShowGraph string `yaml:"showGraph" jsonschema:"enum=always,enum=never,enum=when-maximised"`
|
||||||
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
|
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
|
||||||
ShowWholeGraph bool `yaml:"showWholeGraph"`
|
ShowWholeGraph bool `yaml:"showWholeGraph"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitPrefixConfig struct {
|
type CommitPrefixConfig struct {
|
||||||
// pattern to match on. E.g. for 'feature/AB-123' to match on the AB-123 use "^\\w+\\/(\\w+-\\w+).*"
|
// pattern to match on. E.g. for 'feature/AB-123' to match on the AB-123 use "^\\w+\\/(\\w+-\\w+).*"
|
||||||
Pattern string `yaml:"pattern"`
|
Pattern string `yaml:"pattern" jsonschema:"example=^\\w+\\/(\\w+-\\w+).*,minLength=1"`
|
||||||
// Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] "
|
// Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] "
|
||||||
Replace string `yaml:"replace"`
|
Replace string `yaml:"replace" jsonschema:"example=[$1] ,minLength=1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateConfig struct {
|
type UpdateConfig struct {
|
||||||
// One of: 'prompt' (default) | 'background' | 'never'
|
// One of: 'prompt' (default) | 'background' | 'never'
|
||||||
Method string `yaml:"method"`
|
Method string `yaml:"method" jsonschema:"enum=prompt,enum=background,enum=never"`
|
||||||
// Period in days between update checks
|
// Period in days between update checks
|
||||||
Days int64 `yaml:"days"`
|
Days int64 `yaml:"days" jsonschema:"minimum=0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeybindingConfig struct {
|
type KeybindingConfig struct {
|
||||||
@ -459,7 +471,7 @@ type OSConfig struct {
|
|||||||
|
|
||||||
// A built-in preset that sets all of the above settings. Supported presets
|
// A built-in preset that sets all of the above settings. Supported presets
|
||||||
// are defined in the getPreset function in editor_presets.go.
|
// are defined in the getPreset function in editor_presets.go.
|
||||||
EditPreset string `yaml:"editPreset,omitempty"`
|
EditPreset string `yaml:"editPreset,omitempty" jsonschema:"example=vim,example=nvim,example=emacs,example=nano,example=vscode,example=sublime,example=kakoune,example=helix,example=xcode"`
|
||||||
|
|
||||||
// Command for opening a file, as if the file is double-clicked. Should
|
// Command for opening a file, as if the file is double-clicked. Should
|
||||||
// contain "{{filename}}", but doesn't support "{{line}}".
|
// contain "{{filename}}", but doesn't support "{{line}}".
|
||||||
@ -504,15 +516,15 @@ type CustomCommand struct {
|
|||||||
// The key to trigger the command. Use a single letter or one of the values from https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md
|
// The key to trigger the command. Use a single letter or one of the values from https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md
|
||||||
Key string `yaml:"key"`
|
Key string `yaml:"key"`
|
||||||
// The context in which to listen for the key
|
// The context in which to listen for the key
|
||||||
Context string `yaml:"context"`
|
Context string `yaml:"context" jsonschema:"enum=status,enum=files,enum=worktrees,enum=localBranches,enum=remotes,enum=remoteBranches,enum=tags,enum=commits,enum=reflogCommits,enum=subCommits,enum=commitFiles,enum=stash,enum=global"`
|
||||||
// The command to run (using Go template syntax for placeholder values)
|
// The command to run (using Go template syntax for placeholder values)
|
||||||
Command string `yaml:"command"`
|
Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD"`
|
||||||
// If true, run the command in a subprocess (e.g. if the command requires user input)
|
// If true, run the command in a subprocess (e.g. if the command requires user input)
|
||||||
Subprocess bool `yaml:"subprocess"`
|
Subprocess bool `yaml:"subprocess"`
|
||||||
// A list of prompts that will request user input before running the final command
|
// A list of prompts that will request user input before running the final command
|
||||||
Prompts []CustomCommandPrompt `yaml:"prompts"`
|
Prompts []CustomCommandPrompt `yaml:"prompts"`
|
||||||
// Text to display while waiting for command to finish
|
// Text to display while waiting for command to finish
|
||||||
LoadingText string `yaml:"loadingText"`
|
LoadingText string `yaml:"loadingText" jsonschema:"example=Loading..."`
|
||||||
// Label for the custom command when displayed in the keybindings menu
|
// Label for the custom command when displayed in the keybindings menu
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
// If true, stream the command's output to the Command Log panel
|
// If true, stream the command's output to the Command Log panel
|
||||||
@ -540,7 +552,7 @@ type CustomCommandPrompt struct {
|
|||||||
|
|
||||||
// The message of the confirmation prompt.
|
// The message of the confirmation prompt.
|
||||||
// Only for confirm prompts.
|
// Only for confirm prompts.
|
||||||
Body string `yaml:"body"`
|
Body string `yaml:"body" jsonschema:"example=Are you sure you want to push to the remote?"`
|
||||||
|
|
||||||
// Menu options.
|
// Menu options.
|
||||||
// Only for menu prompts.
|
// Only for menu prompts.
|
||||||
@ -548,23 +560,23 @@ type CustomCommandPrompt struct {
|
|||||||
|
|
||||||
// The command to run to generate menu options
|
// The command to run to generate menu options
|
||||||
// Only for menuFromCommand prompts.
|
// Only for menuFromCommand prompts.
|
||||||
Command string `yaml:"command"`
|
Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD"`
|
||||||
// The regexp to run specifying groups which are going to be kept from the command's output.
|
// The regexp to run specifying groups which are going to be kept from the command's output.
|
||||||
// Only for menuFromCommand prompts.
|
// Only for menuFromCommand prompts.
|
||||||
Filter string `yaml:"filter"`
|
Filter string `yaml:"filter" jsonschema:"example=.*{{.SelectedRemote.Name }}/(?P<branch>.*)"`
|
||||||
// How to format matched groups from the filter to construct a menu item's value.
|
// How to format matched groups from the filter to construct a menu item's value.
|
||||||
// Only for menuFromCommand prompts.
|
// Only for menuFromCommand prompts.
|
||||||
ValueFormat string `yaml:"valueFormat"`
|
ValueFormat string `yaml:"valueFormat" jsonschema:"example={{ .branch }}"`
|
||||||
// Like valueFormat but for the labels. If `labelFormat` is not specified, `valueFormat` is shown instead.
|
// Like valueFormat but for the labels. If `labelFormat` is not specified, `valueFormat` is shown instead.
|
||||||
// Only for menuFromCommand prompts.
|
// Only for menuFromCommand prompts.
|
||||||
LabelFormat string `yaml:"labelFormat"`
|
LabelFormat string `yaml:"labelFormat" jsonschema:"example={{ .branch | green }}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomCommandSuggestions struct {
|
type CustomCommandSuggestions struct {
|
||||||
// Uses built-in logic to obtain the suggestions. One of 'authors' | 'branches' | 'files' | 'refs' | 'remotes' | 'remoteBranches' | 'tags'
|
// Uses built-in logic to obtain the suggestions. One of 'authors' | 'branches' | 'files' | 'refs' | 'remotes' | 'remoteBranches' | 'tags'
|
||||||
Preset string `yaml:"preset"`
|
Preset string `yaml:"preset" jsonschema:"enum=authors,enum=branches,enum=files,enum=refs,enum=remotes,enum=remoteBranches,enum=tags"`
|
||||||
// Command to run such that each line in the output becomes a suggestion. Mutually exclusive with 'preset' field.
|
// Command to run such that each line in the output becomes a suggestion. Mutually exclusive with 'preset' field.
|
||||||
Command string `yaml:"command"`
|
Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomCommandMenuOption struct {
|
type CustomCommandMenuOption struct {
|
||||||
@ -573,7 +585,7 @@ type CustomCommandMenuOption struct {
|
|||||||
// The second part of the label
|
// The second part of the label
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
// The value that will be used in the command
|
// The value that will be used in the command
|
||||||
Value string `yaml:"value"`
|
Value string `yaml:"value" jsonschema:"example=feature,minLength=1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultConfig() *UserConfig {
|
func GetDefaultConfig() *UserConfig {
|
||||||
|
106
pkg/jsonschema/generate.go
Normal file
106
pkg/jsonschema/generate.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
//go:generate go run generator.go
|
||||||
|
|
||||||
|
package jsonschema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazycore/pkg/utils"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
"github.com/karimkhaleel/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetSchemaDir() string {
|
||||||
|
return utils.GetLazyRootDirectory() + "/schema"
|
||||||
|
}
|
||||||
|
|
||||||
|
func GenerateSchema() {
|
||||||
|
schema := customReflect(&config.UserConfig{})
|
||||||
|
obj, _ := json.MarshalIndent(schema, "", " ")
|
||||||
|
|
||||||
|
if err := os.WriteFile(GetSchemaDir()+"/config.json", obj, 0o644); err != nil {
|
||||||
|
fmt.Println("Error writing to file:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func customReflect(v *config.UserConfig) *jsonschema.Schema {
|
||||||
|
defaultConfig := config.GetDefaultConfig()
|
||||||
|
r := &jsonschema.Reflector{FieldNameTag: "yaml", RequiredFromJSONSchemaTags: true, DoNotReference: true}
|
||||||
|
if err := r.AddGoComments("github.com/jesseduffield/lazygit/pkg/config", "../config"); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
schema := r.Reflect(v)
|
||||||
|
|
||||||
|
setDefaultVals(defaultConfig, schema)
|
||||||
|
|
||||||
|
return schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func setDefaultVals(defaults any, schema *jsonschema.Schema) {
|
||||||
|
t := reflect.TypeOf(defaults)
|
||||||
|
v := reflect.ValueOf(defaults)
|
||||||
|
|
||||||
|
if t.Kind() == reflect.Ptr || t.Kind() == reflect.Interface {
|
||||||
|
t = t.Elem()
|
||||||
|
v = v.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.NumField(); i++ {
|
||||||
|
value := v.Field(i).Interface()
|
||||||
|
parentKey := t.Field(i).Name
|
||||||
|
|
||||||
|
key, ok := schema.OriginalPropertiesMapping[parentKey]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
subSchema, ok := schema.Properties.Get(key)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if isStruct(value) {
|
||||||
|
setDefaultVals(value, subSchema)
|
||||||
|
} else if !isZeroValue(value) {
|
||||||
|
subSchema.Default = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isZeroValue(v any) bool {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case int, int32, int64, float32, float64:
|
||||||
|
return v == 0
|
||||||
|
case string:
|
||||||
|
return v == ""
|
||||||
|
case bool:
|
||||||
|
return !v
|
||||||
|
case nil:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
switch rv.Kind() {
|
||||||
|
case reflect.Slice, reflect.Map:
|
||||||
|
return rv.Len() == 0
|
||||||
|
case reflect.Ptr, reflect.Interface:
|
||||||
|
return rv.IsNil()
|
||||||
|
case reflect.Struct:
|
||||||
|
for i := 0; i < rv.NumField(); i++ {
|
||||||
|
if !isZeroValue(rv.Field(i).Interface()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isStruct(v any) bool {
|
||||||
|
return reflect.TypeOf(v).Kind() == reflect.Struct
|
||||||
|
}
|
14
pkg/jsonschema/generator.go
Normal file
14
pkg/jsonschema/generator.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//go:build ignore
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Printf("Generating jsonschema in %s...\n", jsonschema.GetSchemaDir())
|
||||||
|
jsonschema.GenerateSchema()
|
||||||
|
}
|
1501
schema/config.json
Normal file
1501
schema/config.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user