mirror of
https://github.com/NixOS/nix
synced 2025-06-27 08:31:16 +02:00
* Option --argstr for passing string arguments easily. (NIX-75)
This commit is contained in:
parent
4e329f173f
commit
e418976107
11 changed files with 88 additions and 28 deletions
|
@ -2,11 +2,11 @@ pkglib_LTLIBRARIES = libexpr.la
|
|||
|
||||
libexpr_la_SOURCES = \
|
||||
nixexpr.cc eval.cc primops.cc lexer-tab.cc parser-tab.cc \
|
||||
get-drvs.cc attr-path.cc expr-to-xml.cc
|
||||
get-drvs.cc attr-path.cc expr-to-xml.cc common-opts.cc
|
||||
|
||||
pkginclude_HEADERS = \
|
||||
nixexpr.hh eval.hh parser.hh lexer-tab.hh parser-tab.hh \
|
||||
get-drvs.hh attr-path.hh expr-to-xml.hh
|
||||
get-drvs.hh attr-path.hh expr-to-xml.hh common-opts.hh
|
||||
|
||||
libexpr_la_LIBADD = ../libutil/libutil.la ../libstore/libstore.la \
|
||||
../boost/format/libformat.la
|
||||
|
|
32
src/libexpr/common-opts.cc
Normal file
32
src/libexpr/common-opts.cc
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "common-opts.hh"
|
||||
#include "../libmain/shared.hh"
|
||||
#include "util.hh"
|
||||
#include "parser.hh"
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
||||
bool parseOptionArg(const string & arg, Strings::iterator & i,
|
||||
const Strings::iterator & argsEnd, EvalState & state,
|
||||
ATermMap & autoArgs)
|
||||
{
|
||||
if (arg != "--arg" && arg != "--argstr") return false;
|
||||
|
||||
UsageError error(format("`%1%' requires two arguments") % arg);
|
||||
|
||||
if (i == argsEnd) throw error;
|
||||
string name = *i++;
|
||||
if (i == argsEnd) throw error;
|
||||
string value = *i++;
|
||||
|
||||
Expr e = arg == "--arg"
|
||||
? parseExprFromString(state, value, absPath("."))
|
||||
: makeStr(value);
|
||||
autoArgs.set(toATerm(name), e);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
17
src/libexpr/common-opts.hh
Normal file
17
src/libexpr/common-opts.hh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef __COMMON_OPTS_H
|
||||
#define __COMMON_OPTS_H
|
||||
|
||||
#include "eval.hh"
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
||||
/* Some common option parsing between nix-env and nix-instantiate. */
|
||||
bool parseOptionArg(const string & arg, Strings::iterator & i,
|
||||
const Strings::iterator & argsEnd, EvalState & state,
|
||||
ATermMap & autoArgs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* !__COMMON_OPTS_H */
|
Loading…
Add table
Add a link
Reference in a new issue