@@ -20,32 +20,43 @@ func NewImportCommand(app internal.DbqApp) *cobra.Command {
2020This command is useful for quickly onboarding data from external systems, allowing you to easily access and work with already existing data.
2121` ,
2222 RunE : func (cmd * cobra.Command , args []string ) error {
23- datasets , err := app .ImportDatasets (dataSource , filter )
24- if err != nil {
25- log .Println ("Failed to fetch datasets: " + err .Error ())
26- return nil
23+ var importFromSources []string
24+ if dataSource != "" {
25+ importFromSources = append (importFromSources , dataSource )
26+ } else {
27+ for _ , ds := range app .GetDbqConfig ().DataSources {
28+ importFromSources = append (importFromSources , ds .ID )
29+ }
2730 }
2831
29- log .Printf ("Found %d datasets to import: %v\n " , len (datasets ), datasets )
30- if updateCfg {
32+ for _ , curDataSource := range importFromSources {
33+ datasets , err := app .ImportDatasets (curDataSource , filter )
34+ if err != nil {
35+ log .Println ("Failed to fetch datasets: " + err .Error ())
36+ return nil
37+ }
38+
39+ log .Printf ("Found %d datasets in %s to import: %v\n " , len (datasets ), curDataSource , datasets )
40+
3141 ds := app .FindDataSourceById (dataSource )
3242 if ds != nil {
3343 ds .Datasets = datasets
34- err := app .SaveDbqConfig ()
35- if err != nil {
36- return err
37- }
38- log .Println ("dbq config has been updated" )
3944 }
4045 }
4146
47+ if updateCfg {
48+ err := app .SaveDbqConfig ()
49+ if err != nil {
50+ return err
51+ }
52+ log .Println ("dbq config has been updated" )
53+ }
54+
4255 return nil
4356 },
4457 }
4558
4659 cmd .Flags ().StringVarP (& dataSource , "datasource" , "d" , "" , "Datasource from which datasets will be imported" )
47- _ = cmd .MarkFlagRequired ("datasource" ) // todo: support import from all
48-
4960 cmd .Flags ().StringVarP (& filter , "filter" , "f" , "" , "Filter applied for dataset selection" )
5061 cmd .Flags ().BoolVarP (& updateCfg , "update-checks" , "u" , false , "Update checks config file in place" )
5162
0 commit comments