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