Rename FullSnippet to Fragment and remove unused replace in go.mod

This commit is contained in:
max furman 2021-11-09 17:25:03 -08:00
parent b080b7582b
commit da74fa2eb9
3 changed files with 7 additions and 9 deletions

2
go.mod
View file

@ -49,5 +49,3 @@ require (
//replace go.step.sm/crypto => ../crypto
replace go.step.sm/cli-utils => ../cli-utils
replace go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1 => github.com/omorsi/pkcs7 v0.0.0-20210217142924-a7b80a2a8568

View file

@ -20,8 +20,8 @@ type TemplateType string
const (
// Snippet will mark a template as a part of a file.
Snippet TemplateType = "snippet"
// FullSnippet will mark a template that includes header and footer as a part of a file.
FullSnippet TemplateType = "fullSnippet"
// Fragment will mark a template that includes header and footer as a part of a file.
Fragment TemplateType = "fragment"
// File will mark a templates as a full file.
File TemplateType = "file"
// Directory will mark a template as a directory.
@ -120,8 +120,8 @@ func (t *Template) Validate() error {
return nil
case t.Name == "":
return errors.New("template name cannot be empty")
case t.Type != Snippet && t.Type != File && t.Type != Directory && t.Type != FullSnippet:
return errors.Errorf("invalid template type %s, it must be %s, %s, %s, or %s", t.Type, Snippet, FullSnippet, File, Directory)
case t.Type != Snippet && t.Type != File && t.Type != Directory && t.Type != Fragment:
return errors.Errorf("invalid template type %s, it must be %s, %s, %s, or %s", t.Type, Snippet, Fragment, File, Directory)
case t.TemplatePath == "" && t.Type != Directory && len(t.Content) == 0:
return errors.New("template template cannot be empty")
case t.TemplatePath != "" && t.Type == Directory:
@ -264,9 +264,9 @@ func (o *Output) Write() error {
return fileutil.WriteFile(path, o.Content, 0600)
case Snippet:
return fileutil.WriteSnippet(path, o.Content, 0600)
case FullSnippet:
case Fragment:
lines := strings.Split(string(o.Content), "\n")
return fileutil.WriteFullSnippet(path, o.Content, lines[0], lines[len(lines)-1], 0600)
return fileutil.WriteFragment(path, o.Content, lines[0], lines[len(lines)-1], 0600)
default:
return errors.Errorf("unexpected output template type %s", string(o.Type))
}

View file

@ -23,7 +23,7 @@ var DefaultSSHTemplates = SSHTemplates{
User: []Template{
{
Name: "include.tpl",
Type: FullSnippet,
Type: Fragment,
TemplatePath: "templates/ssh/include.tpl",
Path: "~/.ssh/config",
Comment: "#",