Philipp Stanner: 3
qm: improve user informing
lib: implement search methods and project creation
bin: list: First version of project tree printing
5 files changed, 193 insertions(+), 36 deletions(-)
IMO this makes kind of sense. In the long run I would prefer a `qm init`
command for this. Then the user has full control and `qm` does not do
any magic without being asked.
For now it is fine for me, just quickfix the typo below. :)
PS: Sent by mutt.
[PATCH 2/3] lib: implement search methods and project creation
Export this patch
Implements:
- Projects are now created on collections.
- Layer-Search-Methods for tree-printing of projects
- UUIDs for projects
---
Those are major changes. We will have to find a way to use Container for
all of this soonish.
lib/collection.go | 85 +++++++++++++++++++++++++++++++++++++++++++----lib/container.go | 20 +++++------lib/project.go | 5 ++-
3 files changed, 91 insertions(+), 19 deletions(-)
diff --git a/lib/collection.go b/lib/collection.go
index 37784ff..6a28d35 100644
--- a/lib/collection.go+++ b/lib/collection.go
@@ -23,6 +23,11 @@ const (
SearchAttrTag = "tag"
)
+type ProjectSubTreeS struct {+ Proj *Project+ Subprojs []*ProjectSubTreeS+}+type Collection struct {
Path string
PoolPath string
@@ -99,6 +104,7 @@ func getProjMeta(path string) (*Project, error) {
return proj, nil
}
+// TODO: Works only properly with minimum number = 1. Maybe 0 is better?func buildLayerNGlob(depth uint) string {
var i uint
s := "/"
---
Thanks for your last patch.
I have fixed the global variable and use defer instead.
As for the recursion: Lots of work, we'll keep it, but feel free to
offer a patch adjusting everything in a way you viel as appropriate, and
we can have a discussion about this.
But this code will probably change very quickly anyways.
bin/qm-list/main.go | 116 ++++++++++++++++++++++++++++++++++++++------
1 file changed, 100 insertions(+), 16 deletions(-)
diff --git a/bin/qm-list/main.go b/bin/qm-list/main.go
index 512baca..6f99180 100644
--- a/bin/qm-list/main.go
@@ -2,51 +2,135 @@ package main
import (
"fmt"
+ "os" qm "git.sr.ht/~imperator/quartiermeister/lib"
"github.com/integrii/flaggy"
)
-func listItems(c *qm.Collection) {+type options struct {+ recurse uint+ noLines bool+}++// options should be global, otherwise get passed around 1000 times.+var opts options++func listItems(c *qm.Collection) error { items, err := c.AllItems()
if err != nil {
- fmt.Println("error: ", err)- return+ return err }
for _, i := range items {
fmt.Println(i.Title)
}
++ return nil+}++// creates string prefix for printing a tree+func prefixByDepth(depth int) string {+ if depth == 0 {+ return ""+ }+ prefix := "├─"+ lengthener := "────"+ if opts.noLines {
I prefer groups because it is always a lot clearer to me. No idea why, less
visual noise maybe.
var (
indentation string
prefix = "├─"
lengthener = "────"
)
++// prints passed subproject and all its subprojects recursively+func printProjAndSubs(subproj *qm.ProjectSubTreeS, depth int) error {+ defer decrDepth(&depth)++ // when this function recurses, the recursors get higher and higher+ // numbers, causing the right indentation.+ prefix := prefixByDepth(depth)+ depth += 1++ // TODO: find out why there is a whitespace too much+ fmt.Println(prefix, subproj.Proj.Title)