forked from lix-project/lix
nix flake info: Show flake subdirectory
This commit is contained in:
parent
5f75d56c9b
commit
2287e2f279
|
@ -16,7 +16,10 @@ const static std::string subDirRegex = subDirElemRegex + "(?:/" + subDirElemRege
|
|||
|
||||
std::string FlakeRef::to_string() const
|
||||
{
|
||||
return input->to_string();
|
||||
auto url = input->toURL();
|
||||
if (subdir != "")
|
||||
url.query.insert_or_assign("dir", subdir);
|
||||
return url.to_string();
|
||||
}
|
||||
|
||||
fetchers::Attrs FlakeRef::toAttrs() const
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "path.hh"
|
||||
#include "tree-info.hh"
|
||||
#include "attrs.hh"
|
||||
#include "parse.hh"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
@ -45,7 +46,12 @@ struct Input : std::enable_shared_from_this<Input>
|
|||
|
||||
virtual std::optional<Hash> getRev() const { return {}; }
|
||||
|
||||
virtual std::string to_string() const = 0;
|
||||
virtual ParsedURL toURL() const = 0;
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
return toURL().to_string();
|
||||
}
|
||||
|
||||
Attrs toAttrs() const;
|
||||
|
||||
|
@ -74,8 +80,6 @@ private:
|
|||
virtual Attrs toAttrsInternal() const = 0;
|
||||
};
|
||||
|
||||
struct ParsedURL;
|
||||
|
||||
struct InputScheme
|
||||
{
|
||||
virtual ~InputScheme() { }
|
||||
|
|
|
@ -48,14 +48,14 @@ struct GitInput : Input
|
|||
|
||||
std::optional<Hash> getRev() const override { return rev; }
|
||||
|
||||
std::string to_string() const override
|
||||
ParsedURL toURL() const override
|
||||
{
|
||||
ParsedURL url2(url);
|
||||
if (url2.scheme != "git") url2.scheme = "git+" + url2.scheme;
|
||||
if (rev) url2.query.insert_or_assign("rev", rev->gitRev());
|
||||
if (ref) url2.query.insert_or_assign("ref", *ref);
|
||||
if (shallow) url2.query.insert_or_assign("shallow", "1");
|
||||
return url2.to_string();
|
||||
return url2;
|
||||
}
|
||||
|
||||
Attrs toAttrsInternal() const override
|
||||
|
|
|
@ -42,13 +42,16 @@ struct GitHubInput : Input
|
|||
|
||||
std::optional<Hash> getRev() const override { return rev; }
|
||||
|
||||
std::string to_string() const override
|
||||
ParsedURL toURL() const override
|
||||
{
|
||||
auto s = fmt("github:%s/%s", owner, repo);
|
||||
auto path = owner + "/" + repo;
|
||||
assert(!(ref && rev));
|
||||
if (ref) s += "/" + *ref;
|
||||
if (rev) s += "/" + rev->to_string(Base16, false);
|
||||
return s;
|
||||
if (ref) path += "/" + *ref;
|
||||
if (rev) path += "/" + rev->to_string(Base16, false);
|
||||
return ParsedURL {
|
||||
.scheme = "github",
|
||||
.path = path,
|
||||
};
|
||||
}
|
||||
|
||||
Attrs toAttrsInternal() const override
|
||||
|
|
|
@ -43,14 +43,14 @@ struct IndirectInput : Input
|
|||
&& (!rev || rev == other2->rev);
|
||||
}
|
||||
|
||||
std::string to_string() const override
|
||||
ParsedURL toURL() const override
|
||||
{
|
||||
ParsedURL url;
|
||||
url.scheme = "flake";
|
||||
url.path = id;
|
||||
if (ref) { url.path += '/'; url.path += *ref; };
|
||||
if (rev) { url.path += '/'; url.path += rev->gitRev(); };
|
||||
return url.to_string();
|
||||
return url;
|
||||
}
|
||||
|
||||
Attrs toAttrsInternal() const override
|
||||
|
|
|
@ -42,13 +42,13 @@ struct MercurialInput : Input
|
|||
|
||||
std::optional<Hash> getRev() const override { return rev; }
|
||||
|
||||
std::string to_string() const override
|
||||
ParsedURL toURL() const override
|
||||
{
|
||||
ParsedURL url2(url);
|
||||
url2.scheme = "hg+" + url2.scheme;
|
||||
if (rev) url2.query.insert_or_assign("rev", rev->gitRev());
|
||||
if (ref) url2.query.insert_or_assign("ref", *ref);
|
||||
return url2.to_string();
|
||||
return url;
|
||||
}
|
||||
|
||||
Attrs toAttrsInternal() const override
|
||||
|
|
|
@ -190,7 +190,7 @@ struct TarballInput : Input
|
|||
return hash || narHash;
|
||||
}
|
||||
|
||||
std::string to_string() const override
|
||||
ParsedURL toURL() const override
|
||||
{
|
||||
auto url2(url);
|
||||
// NAR hashes are preferred over file hashes since tar/zip files
|
||||
|
@ -199,7 +199,7 @@ struct TarballInput : Input
|
|||
url2.query.insert_or_assign("narHash", narHash->to_string(SRI));
|
||||
else if (hash)
|
||||
url2.query.insert_or_assign("hash", hash->to_string(SRI));
|
||||
return url2.to_string();
|
||||
return url2;
|
||||
}
|
||||
|
||||
Attrs toAttrsInternal() const override
|
||||
|
|
|
@ -79,7 +79,7 @@ struct CmdFlakeList : EvalCommand
|
|||
|
||||
static void printFlakeInfo(const Store & store, const Flake & flake)
|
||||
{
|
||||
std::cout << fmt("URL: %s\n", flake.lockedRef.input->to_string());
|
||||
std::cout << fmt("URL: %s\n", flake.lockedRef.to_string());
|
||||
std::cout << fmt("Edition: %s\n", flake.edition);
|
||||
if (flake.description)
|
||||
std::cout << fmt("Description: %s\n", *flake.description);
|
||||
|
@ -99,7 +99,7 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
|
|||
if (flake.description)
|
||||
j["description"] = *flake.description;
|
||||
j["edition"] = flake.edition;
|
||||
j["url"] = flake.lockedRef.input->to_string();
|
||||
j["url"] = flake.lockedRef.to_string();
|
||||
if (auto rev = flake.lockedRef.input->getRev())
|
||||
j["revision"] = rev->to_string(Base16, false);
|
||||
if (flake.sourceInfo->info.revCount)
|
||||
|
|
Loading…
Reference in a new issue