1
- #include " nix/cmd/command.hh"
2
- #include " nix/cmd/installable-flake.hh"
1
+ #include " flake-command.hh"
3
2
#include " nix/main/common-args.hh"
4
3
#include " nix/main/shared.hh"
5
4
#include " nix/expr/eval.hh"
6
5
#include " nix/expr/eval-inline.hh"
7
6
#include " nix/expr/eval-settings.hh"
8
- #include " nix/flake/flake.hh"
9
7
#include " nix/expr/get-drvs.hh"
10
8
#include " nix/util/signals.hh"
11
9
#include " nix/store/store-open.hh"
@@ -33,43 +31,36 @@ using namespace nix::flake;
33
31
using json = nlohmann::json;
34
32
35
33
struct CmdFlakeUpdate ;
36
- class FlakeCommand : virtual Args, public MixFlakeOptions
37
- {
38
- protected:
39
- std::string flakeUrl = " ." ;
40
-
41
- public:
42
34
43
- FlakeCommand ()
44
- {
45
- expectArgs ({
46
- .label = " flake-url" ,
47
- .optional = true ,
48
- .handler = {&flakeUrl},
49
- .completer = {[&](AddCompletions & completions, size_t , std::string_view prefix) {
50
- completeFlakeRef (completions, getStore (), prefix);
51
- }}
52
- });
53
- }
35
+ FlakeCommand:: FlakeCommand ()
36
+ {
37
+ expectArgs ({
38
+ .label = " flake-url" ,
39
+ .optional = true ,
40
+ .handler = {&flakeUrl},
41
+ .completer = {[&](AddCompletions & completions, size_t , std::string_view prefix) {
42
+ completeFlakeRef (completions, getStore (), prefix);
43
+ }}
44
+ });
45
+ }
54
46
55
- FlakeRef getFlakeRef ()
56
- {
57
- return parseFlakeRef (fetchSettings, flakeUrl, std::filesystem::current_path ().string ()); // FIXME
58
- }
47
+ FlakeRef FlakeCommand:: getFlakeRef ()
48
+ {
49
+ return parseFlakeRef (fetchSettings, flakeUrl, std::filesystem::current_path ().string ()); // FIXME
50
+ }
59
51
60
- LockedFlake lockFlake ()
61
- {
62
- return flake::lockFlake (flakeSettings, *getEvalState (), getFlakeRef (), lockFlags);
63
- }
52
+ LockedFlake FlakeCommand:: lockFlake ()
53
+ {
54
+ return flake::lockFlake (flakeSettings, *getEvalState (), getFlakeRef (), lockFlags);
55
+ }
64
56
65
- std::vector<FlakeRef> getFlakeRefsForCompletion () override
66
- {
67
- return {
68
- // Like getFlakeRef but with expandTilde called first
69
- parseFlakeRef (fetchSettings, expandTilde (flakeUrl), std::filesystem::current_path ().string ())
70
- };
71
- }
72
- };
57
+ std::vector<FlakeRef> FlakeCommand::getFlakeRefsForCompletion ()
58
+ {
59
+ return {
60
+ // Like getFlakeRef but with expandTilde called first
61
+ parseFlakeRef (fetchSettings, expandTilde (flakeUrl), std::filesystem::current_path ().string ())
62
+ };
63
+ }
73
64
74
65
struct CmdFlakeUpdate : FlakeCommand
75
66
{
@@ -1528,21 +1519,7 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
1528
1519
struct CmdFlake : NixMultiCommand
1529
1520
{
1530
1521
CmdFlake ()
1531
- : NixMultiCommand(
1532
- " flake" ,
1533
- {
1534
- {" update" , []() { return make_ref<CmdFlakeUpdate>(); }},
1535
- {" lock" , []() { return make_ref<CmdFlakeLock>(); }},
1536
- {" metadata" , []() { return make_ref<CmdFlakeMetadata>(); }},
1537
- {" info" , []() { return make_ref<CmdFlakeInfo>(); }},
1538
- {" check" , []() { return make_ref<CmdFlakeCheck>(); }},
1539
- {" init" , []() { return make_ref<CmdFlakeInit>(); }},
1540
- {" new" , []() { return make_ref<CmdFlakeNew>(); }},
1541
- {" clone" , []() { return make_ref<CmdFlakeClone>(); }},
1542
- {" archive" , []() { return make_ref<CmdFlakeArchive>(); }},
1543
- {" show" , []() { return make_ref<CmdFlakeShow>(); }},
1544
- {" prefetch" , []() { return make_ref<CmdFlakePrefetch>(); }},
1545
- })
1522
+ : NixMultiCommand(" flake" , RegisterCommand::getCommandsFor({" flake" }))
1546
1523
{
1547
1524
}
1548
1525
@@ -1566,3 +1543,14 @@ struct CmdFlake : NixMultiCommand
1566
1543
};
1567
1544
1568
1545
static auto rCmdFlake = registerCommand<CmdFlake>(" flake" );
1546
+ static auto rCmdFlakeArchive = registerCommand2<CmdFlakeArchive>({" flake" , " archive" });
1547
+ static auto rCmdFlakeCheck = registerCommand2<CmdFlakeCheck>({" flake" , " check" });
1548
+ static auto rCmdFlakeClone = registerCommand2<CmdFlakeClone>({" flake" , " clone" });
1549
+ static auto rCmdFlakeInfo = registerCommand2<CmdFlakeInfo>({" flake" , " info" });
1550
+ static auto rCmdFlakeInit = registerCommand2<CmdFlakeInit>({" flake" , " init" });
1551
+ static auto rCmdFlakeLock = registerCommand2<CmdFlakeLock>({" flake" , " lock" });
1552
+ static auto rCmdFlakeMetadata = registerCommand2<CmdFlakeMetadata>({" flake" , " metadata" });
1553
+ static auto rCmdFlakeNew = registerCommand2<CmdFlakeNew>({" flake" , " new" });
1554
+ static auto rCmdFlakePrefetch = registerCommand2<CmdFlakePrefetch>({" flake" , " prefetch" });
1555
+ static auto rCmdFlakeShow = registerCommand2<CmdFlakeShow>({" flake" , " show" });
1556
+ static auto rCmdFlakeUpdate = registerCommand2<CmdFlakeUpdate>({" flake" , " update" });
0 commit comments