Skip to content

Commit

Permalink
🐛 regression - extracommands require a valid PROJECT file again
Browse files Browse the repository at this point in the history
* Handle failing on 3-alpha configs
* Set project fields to default if the stable version is registered

Signed-off-by: jesus m. rodriguez <jesusr@redhat.com>
  • Loading branch information
jmrodri committed Apr 8, 2021
1 parent 84f357b commit 5c61117
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,25 @@ func newCLI(options ...Option) (*CLI, error) {
func (c *CLI) buildCmd() error {
c.cmd = c.newRootCmd()

var uve config.UnsupportedVersionError

// Get project version and plugin keys.
if err := c.getInfo(); err != nil {
switch err := c.getInfo(); {
case err == nil:
case errors.As(err, &uve):
if !uve.Version.IsStable() {
// Check if the corresponding stable version exists, set c.projectVersion and break
stableVersion := config.Version{
Number: uve.Version.Number,
}
if config.IsRegistered(stableVersion) {
// Get project version and plugin info from defaults
c.getInfoFromDefaults()
}
break
}
fallthrough
default:
return err
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/config/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ limitations under the License.

package config

import "fmt"

var (
registry = make(map[Version]func() Config)
)

// Register allows implementations of Config to register themselves so that they can be created with New
func Register(version Version, constructor func() Config) {
fmt.Printf("Registring %v\n", version)
registry[version] = constructor
}

func IsRegistered(version Version) bool {
_, ok := registry[version]
fmt.Printf("Is %v registered? %v\n", version, ok)
return ok
}

// New creates Config instances from the previously registered implementations through Register
func New(version Version) (Config, error) {
if constructor, exists := registry[version]; exists {
Expand Down

0 comments on commit 5c61117

Please sign in to comment.