Skip to content

Commit

Permalink
feat:support downloading files to specific directories
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxxibo committed Jan 23, 2024
1 parent cad071c commit 97ce84c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/arctl/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ arctl -narcadia eval --rag=<rag-name>
os.Exit(1)
}
ragName, _ := cmd.Flags().GetString("rag")
dir, _ := cmd.Flags().GetString("dir")
rag := evalv1alpha1.RAG{}
gv := evalv1alpha1.GroupVersion.String()
u, err := common.ResourceGet(cmd.Context(), kubeClient, generated.TypedObjectReferenceInput{
Expand All @@ -94,10 +95,11 @@ arctl -narcadia eval --rag=<rag-name>
os.Exit(1)
}

download(cmd.Context(), &rag, kubeClient)
download(cmd.Context(), &rag, kubeClient, dir)
},
}
cmd.Flags().String("rag", "", "rag name")
cmd.Flags().String("dir", ".", "specify the file download directory")
_ = cmd.MarkFlagRequired("rag")
return cmd
}
Expand Down Expand Up @@ -281,7 +283,7 @@ func parseOptions(
return options
}

func download(ctx context.Context, rag *evalv1alpha1.RAG, kubeClient dynamic.Interface) {
func download(ctx context.Context, rag *evalv1alpha1.RAG, kubeClient dynamic.Interface, baseDir string) {
curNamespace := rag.Namespace
clientCache := make(map[string]*downloadutil.Download)
skipSource := make(map[string]struct{})
Expand Down Expand Up @@ -309,7 +311,7 @@ func download(ctx context.Context, rag *evalv1alpha1.RAG, kubeClient dynamic.Int
}

for _, f := range source.Files {
if err := downloader.Download(ctx, downloadutil.WithSrcFile(f), downloadutil.WithDstFile(f)); err != nil {
if err := downloader.Download(ctx, downloadutil.WithSrcFile(f), downloadutil.WithDstFile(filepath.Join(baseDir, f))); err != nil {
fmt.Fprintf(os.Stderr, "datasource %s failed to download file error %s\n", key, err)
}
}
Expand Down

0 comments on commit 97ce84c

Please sign in to comment.