mirror of
https://github.com/NixOS/nix
synced 2025-07-07 18:31:49 +02:00
Merge pull request #13401 from NixOS/split-flake-command
Move FlakeCommand into a header, allow separate registration of subcommands
This commit is contained in:
commit
acfdacc971
3 changed files with 67 additions and 53 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "nix/util/canon-path.hh"
|
#include "nix/util/canon-path.hh"
|
||||||
#include "nix/main/common-args.hh"
|
#include "nix/main/common-args.hh"
|
||||||
#include "nix/expr/search-path.hh"
|
#include "nix/expr/search-path.hh"
|
||||||
|
#include "nix/expr/eval-settings.hh"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
@ -15,10 +16,8 @@ class Store;
|
||||||
namespace fetchers { struct Settings; }
|
namespace fetchers { struct Settings; }
|
||||||
|
|
||||||
class EvalState;
|
class EvalState;
|
||||||
struct EvalSettings;
|
|
||||||
struct CompatibilitySettings;
|
struct CompatibilitySettings;
|
||||||
class Bindings;
|
class Bindings;
|
||||||
struct SourcePath;
|
|
||||||
|
|
||||||
namespace flake { struct Settings; }
|
namespace flake { struct Settings; }
|
||||||
|
|
||||||
|
|
27
src/nix/flake-command.hh
Normal file
27
src/nix/flake-command.hh
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "nix/cmd/command.hh"
|
||||||
|
#include "nix/cmd/installable-flake.hh"
|
||||||
|
#include "nix/flake/flake.hh"
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
using namespace nix::flake;
|
||||||
|
|
||||||
|
class FlakeCommand : virtual Args, public MixFlakeOptions
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::string flakeUrl = ".";
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FlakeCommand();
|
||||||
|
|
||||||
|
FlakeRef getFlakeRef();
|
||||||
|
|
||||||
|
LockedFlake lockFlake();
|
||||||
|
|
||||||
|
std::vector<FlakeRef> getFlakeRefsForCompletion() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +1,9 @@
|
||||||
#include "nix/cmd/command.hh"
|
#include "flake-command.hh"
|
||||||
#include "nix/cmd/installable-flake.hh"
|
|
||||||
#include "nix/main/common-args.hh"
|
#include "nix/main/common-args.hh"
|
||||||
#include "nix/main/shared.hh"
|
#include "nix/main/shared.hh"
|
||||||
#include "nix/expr/eval.hh"
|
#include "nix/expr/eval.hh"
|
||||||
#include "nix/expr/eval-inline.hh"
|
#include "nix/expr/eval-inline.hh"
|
||||||
#include "nix/expr/eval-settings.hh"
|
#include "nix/expr/eval-settings.hh"
|
||||||
#include "nix/flake/flake.hh"
|
|
||||||
#include "nix/expr/get-drvs.hh"
|
#include "nix/expr/get-drvs.hh"
|
||||||
#include "nix/util/signals.hh"
|
#include "nix/util/signals.hh"
|
||||||
#include "nix/store/store-open.hh"
|
#include "nix/store/store-open.hh"
|
||||||
|
@ -33,15 +31,9 @@ using namespace nix::flake;
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
struct CmdFlakeUpdate;
|
struct CmdFlakeUpdate;
|
||||||
class FlakeCommand : virtual Args, public MixFlakeOptions
|
|
||||||
|
FlakeCommand::FlakeCommand()
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
std::string flakeUrl = ".";
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
FlakeCommand()
|
|
||||||
{
|
|
||||||
expectArgs({
|
expectArgs({
|
||||||
.label = "flake-url",
|
.label = "flake-url",
|
||||||
.optional = true,
|
.optional = true,
|
||||||
|
@ -50,26 +42,25 @@ public:
|
||||||
completeFlakeRef(completions, getStore(), prefix);
|
completeFlakeRef(completions, getStore(), prefix);
|
||||||
}}
|
}}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
FlakeRef getFlakeRef()
|
FlakeRef FlakeCommand::getFlakeRef()
|
||||||
{
|
{
|
||||||
return parseFlakeRef(fetchSettings, flakeUrl, std::filesystem::current_path().string()); //FIXME
|
return parseFlakeRef(fetchSettings, flakeUrl, std::filesystem::current_path().string()); //FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
LockedFlake lockFlake()
|
LockedFlake FlakeCommand::lockFlake()
|
||||||
{
|
{
|
||||||
return flake::lockFlake(flakeSettings, *getEvalState(), getFlakeRef(), lockFlags);
|
return flake::lockFlake(flakeSettings, *getEvalState(), getFlakeRef(), lockFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FlakeRef> getFlakeRefsForCompletion() override
|
std::vector<FlakeRef> FlakeCommand::getFlakeRefsForCompletion()
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
// Like getFlakeRef but with expandTilde called first
|
// Like getFlakeRef but with expandTilde called first
|
||||||
parseFlakeRef(fetchSettings, expandTilde(flakeUrl), std::filesystem::current_path().string())
|
parseFlakeRef(fetchSettings, expandTilde(flakeUrl), std::filesystem::current_path().string())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
struct CmdFlakeUpdate : FlakeCommand
|
struct CmdFlakeUpdate : FlakeCommand
|
||||||
{
|
{
|
||||||
|
@ -1528,21 +1519,7 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
|
||||||
struct CmdFlake : NixMultiCommand
|
struct CmdFlake : NixMultiCommand
|
||||||
{
|
{
|
||||||
CmdFlake()
|
CmdFlake()
|
||||||
: NixMultiCommand(
|
: NixMultiCommand("flake", RegisterCommand::getCommandsFor({"flake"}))
|
||||||
"flake",
|
|
||||||
{
|
|
||||||
{"update", []() { return make_ref<CmdFlakeUpdate>(); }},
|
|
||||||
{"lock", []() { return make_ref<CmdFlakeLock>(); }},
|
|
||||||
{"metadata", []() { return make_ref<CmdFlakeMetadata>(); }},
|
|
||||||
{"info", []() { return make_ref<CmdFlakeInfo>(); }},
|
|
||||||
{"check", []() { return make_ref<CmdFlakeCheck>(); }},
|
|
||||||
{"init", []() { return make_ref<CmdFlakeInit>(); }},
|
|
||||||
{"new", []() { return make_ref<CmdFlakeNew>(); }},
|
|
||||||
{"clone", []() { return make_ref<CmdFlakeClone>(); }},
|
|
||||||
{"archive", []() { return make_ref<CmdFlakeArchive>(); }},
|
|
||||||
{"show", []() { return make_ref<CmdFlakeShow>(); }},
|
|
||||||
{"prefetch", []() { return make_ref<CmdFlakePrefetch>(); }},
|
|
||||||
})
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1566,3 +1543,14 @@ struct CmdFlake : NixMultiCommand
|
||||||
};
|
};
|
||||||
|
|
||||||
static auto rCmdFlake = registerCommand<CmdFlake>("flake");
|
static auto rCmdFlake = registerCommand<CmdFlake>("flake");
|
||||||
|
static auto rCmdFlakeArchive = registerCommand2<CmdFlakeArchive>({"flake", "archive"});
|
||||||
|
static auto rCmdFlakeCheck = registerCommand2<CmdFlakeCheck>({"flake", "check"});
|
||||||
|
static auto rCmdFlakeClone = registerCommand2<CmdFlakeClone>({"flake", "clone"});
|
||||||
|
static auto rCmdFlakeInfo = registerCommand2<CmdFlakeInfo>({"flake", "info"});
|
||||||
|
static auto rCmdFlakeInit = registerCommand2<CmdFlakeInit>({"flake", "init"});
|
||||||
|
static auto rCmdFlakeLock = registerCommand2<CmdFlakeLock>({"flake", "lock"});
|
||||||
|
static auto rCmdFlakeMetadata = registerCommand2<CmdFlakeMetadata>({"flake", "metadata"});
|
||||||
|
static auto rCmdFlakeNew = registerCommand2<CmdFlakeNew>({"flake", "new"});
|
||||||
|
static auto rCmdFlakePrefetch = registerCommand2<CmdFlakePrefetch>({"flake", "prefetch"});
|
||||||
|
static auto rCmdFlakeShow = registerCommand2<CmdFlakeShow>({"flake", "show"});
|
||||||
|
static auto rCmdFlakeUpdate = registerCommand2<CmdFlakeUpdate>({"flake", "update"});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue