diff --git a/internal/dependencymanager/dependencyinstaller.go b/internal/dependencymanager/dependencyinstaller.go index 882df2c69..cae67bb78 100644 --- a/internal/dependencymanager/dependencyinstaller.go +++ b/internal/dependencymanager/dependencyinstaller.go @@ -147,6 +147,7 @@ func NewDependencyInstaller(logger output.Logger, state *flowkit.State, saveStat SkipDeployments: flags.skipDeployments, SkipAlias: flags.skipAlias, dependencies: make(map[string]config.Dependency), + logs: categorizedLogs{}, }, nil } @@ -176,8 +177,6 @@ func (di *DependencyInstaller) Install() error { return fmt.Errorf("error saving state: %w", err) } - di.logs.LogAll(di.Logger) - return nil } @@ -240,8 +239,6 @@ func (di *DependencyInstaller) Add(dep config.Dependency) error { return err } - di.logs.LogAll(di.Logger) - return nil } @@ -257,8 +254,6 @@ func (di *DependencyInstaller) AddMany(dependencies []config.Dependency) error { return err } - di.logs.LogAll(di.Logger) - return nil } diff --git a/internal/dependencymanager/install.go b/internal/dependencymanager/install.go index 9c49a5336..8916b261c 100644 --- a/internal/dependencymanager/install.go +++ b/internal/dependencymanager/install.go @@ -42,7 +42,8 @@ var installCommand = &command.Command{ Short: "Install contract and dependencies.", Example: `flow dependencies install flow dependencies install testnet://0afe396ebc8eee65.FlowToken -flow dependencies install FlowToken`, +flow dependencies install FlowToken +flow dependencies install FlowToken NonFungibleToken`, Args: cobra.ArbitraryArgs, }, Flags: &installFlags, @@ -56,49 +57,57 @@ func install( flow flowkit.Services, state *flowkit.State, ) (result command.Result, err error) { - if len(args) > 0 { - logger.Info(fmt.Sprintf("%s Installing dependency %s...", util.PrintEmoji("🔄"), args[0])) - - dep := args[0] + installer, err := NewDependencyInstaller(logger, state, true, "", installFlags) + if err != nil { + logger.Error(fmt.Sprintf("Error initializing dependency installer: %v", err)) + return nil, err + } - installer, err := NewDependencyInstaller(logger, state, true, "", installFlags) - if err != nil { - logger.Error(fmt.Sprintf("Error: %v", err)) - return nil, err - } + if len(args) > 0 { + for _, dep := range args { + logger.Info(fmt.Sprintf("%s Processing dependency %s...", util.PrintEmoji("🔄"), dep)) + + // Check if the dependency is a core contract + coreContractName := findCoreContractCaseInsensitive(dep) + if coreContractName != "" { + if err := installer.AddByCoreContractName(coreContractName); err != nil { + logger.Error(fmt.Sprintf("Error adding core contract %s: %v", coreContractName, err)) + return nil, err + } + continue + } - // Check if the dependency is a core contract - coreContractName := findCoreContractCaseInsensitive(dep) - if coreContractName != "" { - if err := installer.AddByCoreContractName(coreContractName); err != nil { - logger.Error(fmt.Sprintf("Error: %v", err)) + if err := installer.AddBySourceString(dep); err != nil { + if strings.Contains(err.Error(), "invalid dependency source format") { + logger.Error(fmt.Sprintf("Error: '%s' is neither a core contract nor a valid dependency source format.\nPlease provide a valid dependency source in the format 'network://address.ContractName', e.g., 'testnet://0x1234567890abcdef.MyContract', or use a valid core contract name such as 'FlowToken'.", dep)) + } else { + logger.Error(fmt.Sprintf("Error adding dependency %s: %v", dep, err)) + } return nil, err } - return nil, nil } - // Otherwise, add the dependency by source string - if err := installer.AddBySourceString(dep); err != nil { - logger.Error(fmt.Sprintf("Error: %v", err)) + logger.Info(util.MessageWithEmojiPrefix("🔄", "Installing added dependencies...")) + + if err := installer.Install(); err != nil { + logger.Error(fmt.Sprintf("Error installing dependencies: %v", err)) return nil, err } + installer.logs.LogAll(logger) + return nil, nil } logger.Info(util.MessageWithEmojiPrefix("🔄", "Installing dependencies from flow.json...")) - installer, err := NewDependencyInstaller(logger, state, true, "", installFlags) - if err != nil { - logger.Error(fmt.Sprintf("Error: %v", err)) - return nil, err - } - if err := installer.Install(); err != nil { - logger.Error(fmt.Sprintf("Error: %v", err)) + logger.Error(fmt.Sprintf("Error installing dependencies: %v", err)) return nil, err } + installer.logs.LogAll(logger) + return nil, nil }