@@ -12,6 +12,7 @@ import (
1212 "github.com/azure/azure-dev/cli/azd/pkg/ioc"
1313)
1414
15+ // SourceKind represents the type of extension source.
1516type SourceKind string
1617
1718const (
@@ -28,12 +29,14 @@ var (
2829 ErrSourceTypeInvalid = errors .New ("invalid extension source type" )
2930)
3031
32+ // SourceConfig represents the configuration for an extension source.
3133type SourceConfig struct {
3234 Name string `json:"name,omitempty"`
3335 Type SourceKind `json:"type,omitempty"`
3436 Location string `json:"location,omitempty"`
3537}
3638
39+ // SourceManager manages extension sources.
3740type SourceManager struct {
3841 serviceLocator ioc.ServiceLocator
3942 configManager config.UserConfigManager
@@ -52,6 +55,7 @@ func NewSourceManager(
5255 }
5356}
5457
58+ // Get returns an extension source by name.
5559func (sm * SourceManager ) Get (ctx context.Context , name string ) (* SourceConfig , error ) {
5660 sources , err := sm .List (ctx )
5761 if err != nil {
@@ -68,6 +72,7 @@ func (sm *SourceManager) Get(ctx context.Context, name string) (*SourceConfig, e
6872
6973}
7074
75+ // Add adds a new extension source.
7176func (sm * SourceManager ) Add (ctx context.Context , name string , source * SourceConfig ) error {
7277 newKey := normalizeKey (name )
7378
@@ -85,6 +90,7 @@ func (sm *SourceManager) Add(ctx context.Context, name string, source *SourceCon
8590 return sm .addInternal (source )
8691}
8792
93+ // Remove removes an extension source.
8894func (sm * SourceManager ) Remove (ctx context.Context , name string ) error {
8995 name = normalizeKey (name )
9096
@@ -117,6 +123,7 @@ func (sm *SourceManager) Remove(ctx context.Context, name string) error {
117123 return nil
118124}
119125
126+ // List returns a list of extension sources.
120127func (sm * SourceManager ) List (ctx context.Context ) ([]* SourceConfig , error ) {
121128 config , err := sm .configManager .Load ()
122129 if err != nil {
@@ -184,6 +191,7 @@ func (sm *SourceManager) CreateSource(ctx context.Context, config *SourceConfig)
184191 return source , nil
185192}
186193
194+ // addInternal adds a new extension source to the user configuration.
187195func (sm * SourceManager ) addInternal (source * SourceConfig ) error {
188196 config , err := sm .configManager .Load ()
189197 if err != nil {
@@ -204,6 +212,7 @@ func (sm *SourceManager) addInternal(source *SourceConfig) error {
204212 return nil
205213}
206214
215+ // normalizeKey normalizes a key for use in the configuration.
207216func normalizeKey (key string ) string {
208217 key = strings .ToLower (key )
209218 key = strings .ReplaceAll (key , " " , "-" )
0 commit comments