Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
command.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file flox/core/command.hh
4 *
5 * @brief Executable command helpers, argument parsers, etc.
6 *
7 *
8 * -------------------------------------------------------------------------- */
9
10#pragma once
11
12#include <memory>
13#include <string>
14#include <string_view>
15
16#include <argparse/argparse.hpp>
17#include <nix/flake/flakeref.hh>
18
21#include "flox/core/types.hh"
22#include "flox/core/util.hh"
23#include "flox/registry.hh"
24
25
26/* -------------------------------------------------------------------------- */
27
29namespace flox::command {
30
31/* -------------------------------------------------------------------------- */
32
48struct VerboseParser : public argparse::ArgumentParser
49{
50 explicit VerboseParser( const std::string & name,
51 const std::string & version = "0.1.0" );
52}; /* End struct `VerboseParser' */
53
54
55/* -------------------------------------------------------------------------- */
56
58class InlineInputMixin : virtual public NixState
59{
60
61private:
62
63 RegistryInput registryInput;
64
65protected:
66
71 void
72 parseFlakeRef( const std::string & flakeRef )
73 {
74 this->registryInput.from
75 = std::make_shared<nix::FlakeRef>( flox::parseFlakeRef( flakeRef ) );
76 }
77
78
79public:
80
81 argparse::Argument &
82 addSubtreeArg( argparse::ArgumentParser & parser );
83 argparse::Argument &
84 addFlakeRefArg( argparse::ArgumentParser & parser );
85
90 [[nodiscard]] const RegistryInput &
92 {
93 return this->registryInput;
94 }
95
96}; /* End struct `InlineInputMixin' */
97
98
99/* -------------------------------------------------------------------------- */
100
103{
104
105 flox::AttrPath attrPath;
106
112 argparse::Argument &
113 addAttrPathArgs( argparse::ArgumentParser & parser );
114
121 void
123
124}; /* End struct `AttrPathMixin' */
125
126
127/* -------------------------------------------------------------------------- */
128
139/* -------------------------------------------------------------------------- */
140
141} // namespace flox::command
142
143
144/* -------------------------------------------------------------------------- *
145 *
146 *
147 *
148 * ========================================================================== */
Runtime state containing a nix store connection and a nix evaluator.
Definition: nix-state.hh:123
Extend a command's state blob with a single RegistryInput.
Definition: command.hh:59
const RegistryInput & getRegistryInput()
Return the parsed RegistryInput.
Definition: command.hh:91
void parseFlakeRef(const std::string &flakeRef)
Fill registryInput by parsing a flake ref.
Definition: command.hh:72
An exception thrown when a command line argument is invalid.
Definitions of various std::exception children used for throwing errors with nice messages and typed ...
#define FLOX_DEFINE_EXCEPTION(NAME, ERROR_CODE, CATEGORY_MSG)
Generate a class definition with an error code and category message.
Definition: exceptions.hh:206
Executable command helpers, argument parsers, etc.
Definition: command.cc:29
@ EC_INVALID_ARG
Definition: exceptions.hh:37
nix::FlakeRef parseFlakeRef(const std::string &flakeRef)
Parse a flake reference from either a JSON attrset or URI string.
Definition: util.cc:76
std::vector< std::string > AttrPath
A list of key names addressing a location in a nested JSON-like object.
Definition: types.hh:33
Manages a nix runtime state blob with associated helpers.
A set of user inputs used to set input preferences during search and resolution.
Preferences associated with a named registry input.
Definition: registry.hh:135
std::shared_ptr< nix::FlakeRef > from
Definition: registry.hh:141
Extend a command state blob with an attribute path to "target".
Definition: command.hh:103
void fixupAttrPath()
Sets fallback attrPath to a package set.
Definition: command.cc:127
argparse::Argument & addAttrPathArgs(argparse::ArgumentParser &parser)
Sets the attribute path to be scraped.
Definition: command.cc:115
Add verbosity flags to any parser and modify the global verbosity.
Definition: command.hh:49
Miscellaneous typedefs and aliases.
Miscellaneous helper functions.