templates

package
v0.0.0-...-31fe15a Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SourceDefault = &SourceConfig{
		Key:  "default",
		Name: "Default",
		Type: SourceKindResource,
	}

	SourceAwesomeAzd = &SourceConfig{
		Key:      "awesome-azd",
		Name:     "Awesome AZD",
		Type:     SourceKindAwesomeAzd,
		Location: "https://aka.ms/awesome-azd/templates.json",
	}

	WellKnownSources = map[string]*SourceConfig{
		SourceDefault.Key:    SourceDefault,
		SourceAwesomeAzd.Key: SourceAwesomeAzd,
	}

	ErrSourceNotFound    = errors.New("template source not found")
	ErrSourceExists      = errors.New("template source already exists")
	ErrSourceTypeInvalid = errors.New("invalid template source type")
)
View Source
var (
	ErrTemplateNotFound = fmt.Errorf("template not found")
)

Functions

func Absolute

func Absolute(path string) (string, error)

Absolute returns an absolute template path, given a possibly relative template path. An absolute path also corresponds to a fully-qualified URI to a git repository.

See Template.Path for more details.

func Hyperlink(path string) string

Hyperlink returns a hyperlink to the given template path. If the path is cannot be resolved absolutely, it is returned as-is.

Types

type ListOptions

type ListOptions struct {
	Source string
	Tags   []string
}

type Metadata

type Metadata struct {
	Variables map[string]string `json:"variables,omitempty"`
	Config    map[string]string `json:"config,omitempty"`
	Project   map[string]string `json:"project,omitempty"`
}

Metadata contains additional metadata about the template This metadata is used to modify azd project, environment config and environment variables during azd init commands.

type Source

type Source interface {
	// Name returns the name of the source.
	Name() string
	// ListTemplates returns a list of AZD compatible templates.
	ListTemplates(ctx context.Context) ([]*Template, error)
	// GetTemplate returns a template by path.
	GetTemplate(ctx context.Context, path string) (*Template, error)
}

Source is a source of AZD compatible templates.

func NewAwesomeAzdTemplateSource

func NewAwesomeAzdTemplateSource(
	ctx context.Context,
	name string,
	url string,
	httpClient httputil.HttpClient,
) (Source, error)

NewAwesomeAzdTemplateSource creates a new template source from the awesome-azd templates json file.

func NewFileTemplateSource

func NewFileTemplateSource(name string, path string) (Source, error)

NewFileTemplateSource creates a new template source from a file.

func NewJsonTemplateSource

func NewJsonTemplateSource(name string, jsonTemplates string) (Source, error)

NewJsonTemplateSource creates a new template source from a JSON string.

func NewTemplateSource

func NewTemplateSource(name string, templates []*Template) (Source, error)

NewJsonTemplateSource creates a new template source from a JSON string.

func NewUrlTemplateSource

func NewUrlTemplateSource(ctx context.Context, name string, url string, httpClient httputil.HttpClient) (Source, error)

NewUrlTemplateSource creates a new template source from a URL.

type SourceConfig

type SourceConfig struct {
	Key      string     `json:"key,omitempty"`
	Name     string     `json:"name,omitempty"`
	Type     SourceKind `json:"type,omitempty"`
	Location string     `json:"location,omitempty"`
}

type SourceKind

type SourceKind string
const (
	SourceKindFile       SourceKind = "file"
	SourceKindUrl        SourceKind = "url"
	SourceKindResource   SourceKind = "resource"
	SourceKindAwesomeAzd SourceKind = "awesome-azd"
)

type SourceManager

type SourceManager interface {
	// List returns a list of template sources.
	List(ctx context.Context) ([]*SourceConfig, error)
	// Get returns a template source by name.
	Get(ctx context.Context, name string) (*SourceConfig, error)
	// Add adds a new template source.
	Add(ctx context.Context, key string, source *SourceConfig) error
	// Remove removes a template source.
	Remove(ctx context.Context, name string) error
	// CreateSource creates a new template source from a source configuration
	CreateSource(ctx context.Context, source *SourceConfig) (Source, error)
}

SourceManager manages template sources used in azd template list and azd init experiences.

func NewSourceManager

func NewSourceManager(
	options *SourceOptions,
	serviceLocator ioc.ServiceLocator,
	configManager config.UserConfigManager,
	httpClient httputil.HttpClient,
) SourceManager

NewSourceManager creates a new SourceManager.

type SourceOptions

type SourceOptions struct {
	// List of default template sources to use for listing templates
	DefaultSources []*SourceConfig
	// Whether to load template sources from azd configuration
	LoadConfiguredSources bool
}

SourceOptions defines options for the SourceManager.

func NewSourceOptions

func NewSourceOptions() *SourceOptions

NewSourceOptions creates a new SourceOptions with default values

type Template

type Template struct {
	Id string `json:"id"`

	// Name is the friendly short name of the template.
	Name string `json:"name"`

	// The source of the template
	Source string `json:"source,omitempty"`

	// Description is a long description of the template.
	Description string `json:"description,omitempty"`

	// RepositoryPath is a fully qualified URI to a git repository,
	// "{owner}/{repo}" for GitHub repositories,
	// or "{repo}" for GitHub repositories under Azure-Samples (default organization).
	RepositoryPath string `json:"repositoryPath"`

	// A list of tags associated with the template
	Tags []string `json:"tags"`

	// Additional metadata about the template
	Metadata Metadata `json:"metadata,omitempty"`
}

func PromptTemplate

func PromptTemplate(
	ctx context.Context,
	message string,
	templateManager *TemplateManager,
	console input.Console,
	options *ListOptions,
) (*Template, error)

PromptTemplate asks the user to select a template. An empty Template can be returned if the user selects the minimal template. This corresponds to the minimal azd template. See

func (*Template) Display

func (t *Template) Display(writer io.Writer) error

Display writes a string representation of the template suitable for display.

type TemplateManager

type TemplateManager struct {
	// contains filtered or unexported fields
}

func NewTemplateManager

func NewTemplateManager(sourceManager SourceManager, console input.Console) (*TemplateManager, error)

func (*TemplateManager) GetTemplate

func (tm *TemplateManager) GetTemplate(ctx context.Context, path string) (*Template, error)

func (*TemplateManager) ListTemplates

func (tm *TemplateManager) ListTemplates(ctx context.Context, options *ListOptions) ([]*Template, error)

ListTemplates retrieves the list of templates in a deterministic order.

Jump to

Keyboard shortcuts

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