~imperator/quartiermeister-devel

lib: remove obsolete file v1 SUPERSEDED

Philipp Stanner: 2
 lib: remove obsolete file
 all: base all Create functions on a Collection

 6 files changed, 36 insertions(+), 23 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~imperator/quartiermeister-devel/patches/20808/mbox | git am -3
Learn more about email & git

[PATCH 1/2] lib: remove obsolete file Export this patch

---
 lib/groundlayer.go | 1 -
 1 file changed, 1 deletion(-)
 delete mode 100644 lib/groundlayer.go

diff --git a/lib/groundlayer.go b/lib/groundlayer.go
deleted file mode 100644
index 86f2d04..0000000
--- a/lib/groundlayer.go
@@ -1 +0,0 @@
package qm
-- 
2.20.1

[PATCH 2/2] all: base all Create functions on a Collection Export this patch

(except tag.go so far). Later will save trouble with quick envvar
changes
---
 bin/qm-create/main.go |  4 ++--
 lib/container.go      | 23 +++++++++++++++--------
 lib/item.go           |  4 ++--
 lib/project.go        | 11 ++++++++---
 lib/tag.go            | 16 +++++++++-------
 5 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/bin/qm-create/main.go b/bin/qm-create/main.go
index c7a23a1..4c74c18 100644
--- a/bin/qm-create/main.go
@@ -25,7 +25,7 @@ func setParent(c *qm.Collection, it *qm.Item, parent string) error {
}

func createItem(c *qm.Collection, opts *options) error {
	it, err := qm.CreateItem(opts.title, opts.descr)
	it, err := c.CreateItem(opts.title, opts.descr)
	if err != nil {
		return err
	}
@@ -44,7 +44,7 @@ func createItem(c *qm.Collection, opts *options) error {
}

func createProject(c *qm.Collection, opts *options) error {
	pr, err := qm.CreateProject(opts.title, opts.descr, opts.parent)
	pr, err := c.CreateProject(opts.title, opts.descr, opts.parent)
	if err != nil {
		return err
	}
diff --git a/lib/container.go b/lib/container.go
index 0512d54..5859a42 100644
--- a/lib/container.go
+++ b/lib/container.go
@@ -21,20 +21,26 @@ type Container struct {
	parent      string
}

func CreateContainer(title, descr, type_, parent string) *Container {
func checkParentExists(c *Collection, title string) error {
	_, err := c.ProjectByTitle(title)
	return err
}

func (c *Collection) CreateContainer(title,
		descr, type_, parent string) (*Container, error) {
	var path string
	slug := Slug(title)

	if parent == "" {
		path = filepath.Join(CollectionPath(), type_, slug)
		path = filepath.Join(c.Path, type_, slug)
	} else {
		path = filepath.Join(CollectionPath(), type_, parent, slug)
		if err := checkParentExists(c, parent); err != nil {
			return nil, err
		}
		path = filepath.Join(c.Path, type_, parent, slug)
	}

// FIXME: Add check if parent project exists, otherwise project.Flush()
// will MkdirAll it.

	c := &Container{
	cont := &Container{
		Title:       title,
		Slug:        slug,
		Description: descr,
@@ -42,7 +48,8 @@ func CreateContainer(title, descr, type_, parent string) *Container {
		Path:        path,
		parent:      parent,
	}
	return c

	return cont, nil
}

func (c *Container) AssignItem(g *Item) error {
diff --git a/lib/item.go b/lib/item.go
index 13c69c7..7d0c449 100644
--- a/lib/item.go
+++ b/lib/item.go
@@ -31,14 +31,14 @@ type Item struct {
	Tags    []*Tag   `json:"-" yaml:"-"`
}

func CreateItem(title, description string) (*Item, error) {
func (c *Collection) CreateItem(title, description string) (*Item, error) {
	it := &Item{
		Title:       title,
		Slug:        Slug(title),
		Description: description,
		UUID:        uuid.New(),
		CreatedAt:   time.Now(),
		Path:        filepath.Join(PoolPath(), Slug(title)+".qm"),
		Path:        filepath.Join(c.PoolPath, Slug(title)+".qm"),
	}
	return it, nil
}
diff --git a/lib/project.go b/lib/project.go
index 95ad4d6..946b3d0 100644
--- a/lib/project.go
+++ b/lib/project.go
@@ -19,10 +19,15 @@ type Project struct {
	//Progress uint `json:"progress" yaml:"progress"`
}

func CreateProject(title, description, parent string) (*Project, error) {
func (c *Collection) CreateProject(title, description,
		parent string) (*Project, error) {
	p := &Project{}
	c := CreateContainer(title, description, "projects", parent)
	p.Container = *c
	cont, err := c.CreateContainer(title, description, "projects", parent)
	if err != nil {
		return nil, err
	}
	p.Container = *cont

	return p, nil
}

diff --git a/lib/tag.go b/lib/tag.go
index 0349865..7b2359c 100644
--- a/lib/tag.go
+++ b/lib/tag.go
@@ -4,10 +4,12 @@ type Tag struct {
	Container
}

func CreateTag(name, description string) (*Tag, error) {
	var t Tag
	c := CreateContainer(name, description, "tags", "")
	t.Container = *c

	return &t, nil
}
/*
 *func CreateTag(name, description string) (*Tag, error) {
 *        var t Tag
 *        c := CreateContainer(name, description, "tags", "")
 *        t.Container = *c
 *
 *        return &t, nil
 *}
 */
-- 
2.20.1