mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* Define central config * Use envConfig in GenericRun for segment parameters * Pass the env config into the context passed to CLI methods * Use PodmanCmd and DockerCmd from context * Remove tests now that ODO_DISABLE_TELEMETRY is checked for a bool value * deploy.Deploy: Use values from ctx instead of parameters + use FS from DI * dev.Start: Use values from ctx instead of parameters * image.Build*: Use values from ctx instead of parameters * Use telemetry file from context * Pass ctx to segment.getTelemetryForDevfileRegistry * Use ctx in getTelemetryForDevfileRegistry * Call IsTelemetryEnabled once and use scontext.GetTelemetryStatus after * Fix unit tests * Use envConfig in segment.IsTelemetryEnabled * Define TelemetryCaller constant in test helper * IsTrackingConsentEnabled: get value from envconfig instead of env * Use ctx instead of GLOBALODOCONFIG * Place ODO_EXPERIMENTAL_MODE in configuration * Use maintained envconfig package * Define default values when exist * Document accepted boolean values
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package backend
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
|
|
"github.com/devfile/library/pkg/devfile/parser"
|
|
"github.com/redhat-developer/odo/pkg/alizer"
|
|
"github.com/redhat-developer/odo/pkg/api"
|
|
"github.com/redhat-developer/odo/pkg/init/asker"
|
|
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
|
|
)
|
|
|
|
type AlizerBackend struct {
|
|
askerClient asker.Asker
|
|
alizerClient alizer.Client
|
|
}
|
|
|
|
var _ InitBackend = (*AlizerBackend)(nil)
|
|
|
|
func NewAlizerBackend(askerClient asker.Asker, alizerClient alizer.Client) *AlizerBackend {
|
|
return &AlizerBackend{
|
|
askerClient: askerClient,
|
|
alizerClient: alizerClient,
|
|
}
|
|
}
|
|
|
|
func (o *AlizerBackend) Validate(flags map[string]string, fs filesystem.Filesystem, dir string) error {
|
|
return nil
|
|
}
|
|
|
|
// SelectDevfile calls thz Alizer to detect the devfile and asks for confirmation to the user
|
|
func (o *AlizerBackend) SelectDevfile(ctx context.Context, flags map[string]string, fs filesystem.Filesystem, dir string) (location *api.DevfileLocation, err error) {
|
|
selected, registry, err := o.alizerClient.DetectFramework(ctx, dir)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fmt.Printf("Based on the files in the current directory odo detected\nLanguage: %s\nProject type: %s\n", selected.Language, selected.ProjectType)
|
|
fmt.Printf("The devfile %q from the registry %q will be downloaded.\n", selected.Name, registry.Name)
|
|
confirm, err := o.askerClient.AskCorrect()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if !confirm {
|
|
return nil, nil
|
|
}
|
|
return alizer.GetDevfileLocationFromDetection(selected, registry), nil
|
|
}
|
|
|
|
func (o *AlizerBackend) SelectStarterProject(devfile parser.DevfileObj, flags map[string]string) (starter *v1alpha2.StarterProject, err error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (o *AlizerBackend) PersonalizeName(devfile parser.DevfileObj, flags map[string]string) (string, error) {
|
|
// Get the absolute path to the directory from the Devfile context
|
|
path := devfile.Ctx.GetAbsPath()
|
|
if path == "" {
|
|
return "", fmt.Errorf("cannot determine the absolute path of the directory")
|
|
}
|
|
return o.alizerClient.DetectName(path)
|
|
}
|
|
|
|
func (o *AlizerBackend) PersonalizeDevfileConfig(devfile parser.DevfileObj) (parser.DevfileObj, error) {
|
|
return devfile, nil
|
|
}
|