Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AddCmd = &cobra.Command{ Use: "add <space> <path>", Short: "Add a source to a space", Long: wordwrap.WrapString( "Adds a source to a space. A source is currently a path on the local "+ "filesystem, but this may be expanded in the future to include other "+ "types of data sources. `upload` will upload data from all sources "+ "associated with a space. Sources are associated with the space locally "+ "for future local upload commands; no association is made remotely.", 80), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() cfg, err := config.Load[config.Config]() if err != nil { return err } repo, err := preparation.OpenRepo(ctx, cfg.Repo.DatabasePath()) if err != nil { return err } defer repo.Close() space := cmd.Flags().Arg(0) if space == "" { cmd.SilenceUsage = false return errors.New("space cannot be empty") } path := cmd.Flags().Arg(1) if path == "" { cmd.SilenceUsage = false return errors.New("path cannot be empty") } path, err = filepath.Abs(path) if err != nil { return fmt.Errorf("resolving absolute path: %w", err) } spaceDID, err := did.Parse(space) if err != nil { cmd.SilenceUsage = false return fmt.Errorf("parsing space DID: %w", err) } api := preparation.NewAPI(repo, cmdutil.MustGetClient(cfg.Repo.Dir)) // Parse shard size if provided var spaceOptions []model.SpaceOption if addFlags.shardSize != "" { shardSize, err := cmdutil.ParseSize(addFlags.shardSize) if err != nil { return fmt.Errorf("parsing shard size: %w", err) } spaceOptions = append(spaceOptions, model.WithShardSize(shardSize)) } name := path if addFlags.name != "" { name = addFlags.name } _, err = api.FindOrCreateSpace(ctx, spaceDID, spaceDID.String(), spaceOptions...) if err != nil { return fmt.Errorf("command failed to create space: %w", err) } source, err := api.CreateSource(ctx, name, path) if err != nil { return fmt.Errorf("command failed to create source: %w", err) } err = repo.AddSourceToSpace(ctx, spaceDID, source.ID()) if err != nil { return fmt.Errorf("command failed to add source to space: %w", err) } return nil }, }
View Source
var Cmd = &cobra.Command{
Use: "source",
}
View Source
var ListCmd = &cobra.Command{ Use: "list <space>", Aliases: []string{"ls"}, Short: "List sources added to a space", Long: `Lists the sources added to a space.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() cfg, err := config.Load[config.Config]() if err != nil { return err } repo, err := preparation.OpenRepo(ctx, cfg.Repo.DatabasePath()) if err != nil { return err } defer repo.Close() space := cmd.Flags().Arg(0) if space == "" { cmd.SilenceUsage = false return fmt.Errorf("space connot be empty") } spaceDID, err := did.Parse(space) if err != nil { cmd.SilenceUsage = false return fmt.Errorf("parsing space DID: %w", err) } sourceIDs, err := repo.ListSpaceSources(ctx, spaceDID) if err != nil { return err } fmt.Printf("Sources for space %s:\n", spaceDID) for _, sourceID := range sourceIDs { source, err := repo.GetSourceByID(ctx, sourceID) if err != nil { return fmt.Errorf("failed to get source by ID %s: %w", sourceID, err) } if source.Name() != source.Path() { fmt.Printf("- %s: %s\n", source.Name(), source.Path()) } else { fmt.Printf("- %s\n", source.Path()) } } if len(sourceIDs) == 0 { fmt.Printf("No sources found for space %s. Add a source first with:\n\n$ %s %s <path>\n\n", spaceDID, AddCmd.CommandPath(), spaceDID) } return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.