@@ -13,18 +13,21 @@ import (
1313)
1414
1515const (
16- fetchShort = "Sync resources from configured source plugins to destination"
17- fetchExample = `# Sync configured providers to PostgreSQL as configured in cloudquery.yml
18- cloudquery sync ./directory`
16+ fetchShort = "Sync resources from configured source plugins to destinations"
17+ fetchExample = `# Sync resources from configuration in a directory
18+ cloudquery sync ./directory
19+ # Sync resources from directories and files
20+ cloudquery sync ./directory ./aws.yml ./pg.yml
21+ `
1922)
2023
2124func NewCmdSync () * cobra.Command {
2225 cmd := & cobra.Command {
23- Use : "sync [directory ]" ,
26+ Use : "sync [file or directories... ]" ,
2427 Short : fetchShort ,
2528 Long : fetchShort ,
2629 Example : fetchExample ,
27- Args : cobra .MaximumNArgs (1 ),
30+ Args : cobra .MinimumNArgs (1 ),
2831 RunE : sync ,
2932 }
3033 return cmd
@@ -37,29 +40,25 @@ func sync(cmd *cobra.Command, args []string) error {
3740 directory = args [0 ]
3841 }
3942 fmt .Println ("Loading specs from directory: " , directory )
40- specReader , err := specs .NewSpecReader (directory )
43+ specReader , err := specs .NewSpecReader (args )
4144 if err != nil {
4245 return fmt .Errorf ("failed to load specs from directory %s: %w" , directory , err )
4346 }
4447
45- if len (specReader .GetSources ()) == 0 {
46- return fmt .Errorf ("no sources found in directory: %s" , directory )
47- }
48-
4948 pm := plugins .NewPluginManager ()
50- for _ , sourceSpec := range specReader .GetSources () {
49+ for _ , sourceSpec := range specReader .Sources {
5150 if len (sourceSpec .Destinations ) == 0 {
5251 return fmt .Errorf ("no destinations found for source %s" , sourceSpec .Name )
5352 }
5453 var destinationsSpecs []specs.Destination
5554 for _ , destination := range sourceSpec .Destinations {
56- spec := specReader .GetDestinationByName ( destination )
55+ spec := specReader .Destinations [ destination ]
5756 if spec == nil {
5857 return fmt .Errorf ("failed to find destination %s in source %s" , destination , sourceSpec .Name )
5958 }
6059 destinationsSpecs = append (destinationsSpecs , * spec )
6160 }
62- if err := syncConnection (ctx , pm , sourceSpec , destinationsSpecs ); err != nil {
61+ if err := syncConnection (ctx , pm , * sourceSpec , destinationsSpecs ); err != nil {
6362 return fmt .Errorf ("failed to sync source %s: %w" , sourceSpec .Name , err )
6463 }
6564 }
0 commit comments