package config
import (
)
type WorkConfig struct {
File string `json:"file,omitzero"`
}
type WalkConfig struct{}
type VCSConfig struct {
Type string
Git gitvcs.Config
Hg hgvcs.Config
Fossil fossilvcs.Config
JJ jjvcs.Config
}
func ( VCSConfig) () bool { return .Type == "" }
func ( VCSConfig) () string { return cmp.Or(.Type, vcs.BackendAuto) }
func ( *VCSConfig) ( *jsontext.Decoder) error {
* = VCSConfig{}
, := readExternalTag()
if != nil {
return fmt.Errorf("vcs: %w", )
}
, := .Unwrap()
if ! {
return nil
}
switch := .String(); {
case vcs.BackendAuto:
.Type = vcs.BackendAuto
var struct{}
if := json.UnmarshalDecode(, &, json.RejectUnknownMembers(true)); != nil {
return
}
case gitvcs.Name:
.Type = gitvcs.Name
if := json.UnmarshalDecode(, &.Git, json.RejectUnknownMembers(true)); != nil {
return
}
case hgvcs.Name:
.Type = hgvcs.Name
if := json.UnmarshalDecode(, &.Hg, json.RejectUnknownMembers(true)); != nil {
return
}
case fossilvcs.Name:
.Type = fossilvcs.Name
if := json.UnmarshalDecode(, &.Fossil, json.RejectUnknownMembers(true)); != nil {
return
}
case jjvcs.Name:
.Type = jjvcs.Name
if := json.UnmarshalDecode(, &.JJ, json.RejectUnknownMembers(true)); != nil {
return
}
default:
return fmt.Errorf("unknown vcs %q", strings.Clone())
}
if := readExternalTagEnd(); != nil {
return fmt.Errorf("vcs: %w", )
}
return nil
}
func ( VCSConfig) ( *jsontext.Encoder) error {
switch .Type {
case gitvcs.Name:
return marshalExternalTag(, gitvcs.Name, .Git)
case hgvcs.Name:
return marshalExternalTag(, hgvcs.Name, .Hg)
case fossilvcs.Name:
return marshalExternalTag(, fossilvcs.Name, .Fossil)
case jjvcs.Name:
return marshalExternalTag(, jjvcs.Name, .JJ)
default:
return marshalExternalTag(, vcs.BackendAuto, struct{}{})
}
}
type WorkspaceConfig struct {
Type workspace.Mode
Auto WorkConfig
Work WorkConfig
Walk WalkConfig
}
func ( WorkspaceConfig) () bool { return .Type == "" }
func ( WorkspaceConfig) () workspace.Mode { return cmp.Or(.Type, workspace.ModeAuto) }
func ( WorkspaceConfig) () string {
switch .Type {
case workspace.ModeWork:
return .Work.File
case workspace.ModeAuto:
return .Auto.File
default:
return ""
}
}
func ( *WorkspaceConfig) ( *jsontext.Decoder) error {
* = WorkspaceConfig{}
, := readExternalTag()
if != nil {
return fmt.Errorf("workspace: %w", )
}
, := .Unwrap()
if ! {
return nil
}
switch := .String(); workspace.Mode() {
case workspace.ModeAuto:
.Type = workspace.ModeAuto
if := json.UnmarshalDecode(, &.Auto, json.RejectUnknownMembers(true)); != nil {
return
}
case workspace.ModeWork:
.Type = workspace.ModeWork
if := json.UnmarshalDecode(, &.Work, json.RejectUnknownMembers(true)); != nil {
return
}
case workspace.ModeWalk:
.Type = workspace.ModeWalk
if := json.UnmarshalDecode(, &.Walk, json.RejectUnknownMembers(true)); != nil {
return
}
default:
return fmt.Errorf("unknown workspace mode %q", strings.Clone())
}
if := readExternalTagEnd(); != nil {
return fmt.Errorf("workspace: %w", )
}
return nil
}
func ( WorkspaceConfig) ( *jsontext.Encoder) error {
switch .Type {
case workspace.ModeWork:
return marshalExternalTag(, string(workspace.ModeWork), .Work)
case workspace.ModeWalk:
return marshalExternalTag(, string(workspace.ModeWalk), .Walk)
default:
return marshalExternalTag(, string(workspace.ModeAuto), .Auto)
}
}
func ( *jsontext.Encoder, string, any) error {
if := .WriteToken(jsontext.BeginObject); != nil {
return
}
if := .WriteToken(jsontext.String()); != nil {
return
}
if := json.MarshalEncode(, ); != nil {
return
}
return .WriteToken(jsontext.EndObject)
}