diff options
Diffstat (limited to 'src/nix/add-to-store.cc')
-rw-r--r-- | src/nix/add-to-store.cc | 78 |
1 files changed, 46 insertions, 32 deletions
diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index c9d07bdcc..ab2b62da2 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -9,49 +9,22 @@ struct CmdAddToStore : MixDryRun, StoreCommand { Path path; std::optional<std::string> namePart; - FileIngestionMethod ingestionMethod = FileIngestionMethod::Recursive; + FileIngestionMethod ingestionMethod; CmdAddToStore() { + // FIXME: completion expectArg("path", &path); addFlag({ .longName = "name", .shortName = 'n', - .description = "name component of the store path", + .description = "Override the name component of the store path. It defaults to the base name of *path*.", .labels = {"name"}, .handler = {&namePart}, }); - - addFlag({ - .longName = "flat", - .shortName = 0, - .description = "add flat file to the Nix store", - .handler = {&ingestionMethod, FileIngestionMethod::Flat}, - }); - } - - std::string description() override - { - return "add a path to the Nix store"; - } - - std::string doc() override - { - return R"( - Copy the file or directory *path* to the Nix store, and - print the resulting store path on standard output. - )"; - } - - Examples examples() override - { - return { - }; } - Category category() override { return catUtility; } - void run(ref<Store> store) override { if (!namePart) namePart = baseNameOf(path); @@ -89,8 +62,49 @@ struct CmdAddToStore : MixDryRun, StoreCommand store->addToStore(info, source); } - logger->stdout("%s", store->printStorePath(info.path)); + logger->cout("%s", store->printStorePath(info.path)); + } +}; + +struct CmdAddFile : CmdAddToStore +{ + CmdAddFile() + { + ingestionMethod = FileIngestionMethod::Flat; + } + + std::string description() override + { + return "add a regular file to the Nix store"; + } + + std::string doc() override + { + return + #include "add-file.md" + ; + } +}; + +struct CmdAddPath : CmdAddToStore +{ + CmdAddPath() + { + ingestionMethod = FileIngestionMethod::Recursive; + } + + std::string description() override + { + return "add a path to the Nix store"; + } + + std::string doc() override + { + return + #include "add-path.md" + ; } }; -static auto rCmdAddToStore = registerCommand<CmdAddToStore>("add-to-store"); +static auto rCmdAddFile = registerCommand2<CmdAddFile>({"store", "add-file"}); +static auto rCmdAddPath = registerCommand2<CmdAddPath>({"store", "add-path"}); |