Skip to content

Commit

Permalink
Add QuirksCannotAddRemove
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Jun 17, 2024
1 parent 82330a5 commit c69f50b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ const (
// This constant indicates that remove cannot be performed
// without a lockfile.
QuirkRemoveNeedsLockfile

// This constant indicates that the packager is unable to
// add or remove packages.
QuirksCannotAddRemove
)

// LanguageBackend is the core abstraction of UPM. It represents an
Expand Down Expand Up @@ -364,8 +368,8 @@ func (b *LanguageBackend) Setup() {
"missing package dir": b.GetPackageDir == nil,
"missing Search": b.Search == nil,
"missing Info": b.Info == nil,
"missing Add": b.Add == nil,
"missing Remove": b.Remove == nil,
"missing Add": b.QuirksCanAddRemove() && b.Add == nil,
"missing Remove": b.QuirksCanAddRemove() && b.Remove == nil,
"missing IsAvailable": b.IsAvailable == nil,
// The lock method should be unimplemented if
// and only if builds are not reproducible.
Expand Down
6 changes: 6 additions & 0 deletions internal/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ func (b *LanguageBackend) QuirksDoesLockNotAlsoInstall() bool {
func (b *LanguageBackend) QuirkRemoveNeedsLockfile() bool {
return (b.Quirks & QuirkRemoveNeedsLockfile) != 0
}

// QuirksCanAddRemove returns true if the language backend is
// able to add and remove packages
func (b *LanguageBackend) QuirksCanAddRemove() bool {
return (b.Quirks & QuirksCannotAddRemove) == 0
}
10 changes: 10 additions & 0 deletions internal/cli/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ func runAdd(
defer span.Finish()
b := backends.GetBackend(ctx, language)

if !b.QuirksCanAddRemove() {
fmt.Println("This backend does not suppport dependency additions")
os.Exit(1)
}

normPkgs := b.NormalizePackageArgs(args)

if guess {
Expand Down Expand Up @@ -357,6 +362,11 @@ func runRemove(language string, args []string, upgrade bool,
defer span.Finish()
b := backends.GetBackend(ctx, language)

if !b.QuirksCanAddRemove() {
fmt.Println("This backend does not suppport dependency removal")
os.Exit(1)
}

if !util.Exists(b.Specfile) {
return
}
Expand Down

0 comments on commit c69f50b

Please sign in to comment.