templates

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 23 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 DeriveDirectoryName added in v1.24.0

func DeriveDirectoryName(templatePath string) string

DeriveDirectoryName extracts a directory name from a template path, following git clone conventions. For example:

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.

func IsLocalPath

func IsLocalPath(resolvedPath string) bool

IsLocalPath returns true if the given resolved template path refers to a local filesystem directory rather than a remote git URL.

func LooksLikeLocalPath added in v1.24.0

func LooksLikeLocalPath(path string) bool

LooksLikeLocalPath returns true if the path appears to be an explicit local filesystem reference (e.g., ".", "..", starts with ./, ../, or is an absolute path).

func PrintGalleryLinks(w io.Writer)

PrintGalleryLinks prints the template gallery banner message to the given writer.

Types

type GitHubUrlInfo

type GitHubUrlInfo struct {
	// Hostname is the GitHub hostname (e.g., "github.com", "github.enterprise.com")
	Hostname string
	// RepoSlug is the repository in the format "owner/repo"
	RepoSlug string
	// Branch is the branch name, which may contain slashes
	Branch string
	// FilePath is the path to the file within the repository
	FilePath string
}

GitHubUrlInfo contains parsed information from a GitHub URL.

func ParseGitHubUrl

func ParseGitHubUrl(ctx context.Context, urlArg string, ghCli *github.Cli) (*GitHubUrlInfo, error)

ParseGitHubUrl parses various GitHub URL formats and extracts repository information. It supports the following URL formats:

  • https://raw.<hostname>/<owner>/<repo>/<branch>/[...path]/<file>
  • https://<hostname>/<owner>/<repo>/blob/<branch>/[...path]/<file>
  • https://<hostname>/<owner>/<repo>/tree/<branch>/[...path]/<file>
  • https://api.<hostname>/repos/<owner>/<repo>/contents/[...path]/<file>[?ref=<branch>]

Note: Branch names may contain slashes (e.g., "feature/new-feature"). For blob/tree/raw URLs with ambiguous branch/path separation, this function queries the GitHub API to deterministically find the longest valid branch name that exists in the repository.

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.

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"
	SourceKindGh         SourceKind = "gh"
	SourceKindResource   SourceKind = "default"
	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,
	transport policy.Transporter,
) 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"`

	Title string `json:"title,omitempty"`

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

	RepoSource 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"`
}

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.

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