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

pull/692/head
max furman 3 years ago
parent b080b7582b
commit da74fa2eb9

@ -49,5 +49,3 @@ require (
//replace go.step.sm/crypto => ../crypto //replace go.step.sm/crypto => ../crypto
replace go.step.sm/cli-utils => ../cli-utils 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

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

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

Loading…
Cancel
Save