diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-01 09:31:35 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-01 09:31:35 -0600 |
commit | b9fa008b4911a534ff49d191539b57d60cc04663 (patch) | |
tree | ea4aac66c6b187b9522f95c597ed8f7041cd0545 /pkg | |
parent | 539787e5f70776db02e37f74048f9acec2171b0e (diff) |
Add an Item interface
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/btrfs/Makefile | 8 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/items.go | 21 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/items_gen.go | 29 |
3 files changed, 39 insertions, 19 deletions
diff --git a/pkg/btrfs/Makefile b/pkg/btrfs/Makefile index 781eb7c..fc6e9fd 100644 --- a/pkg/btrfs/Makefile +++ b/pkg/btrfs/Makefile @@ -3,19 +3,19 @@ .DELETE_ON_ERROR: btrfsitem/items.txt: btrfsitem $(wildcard btrfsitem/item_*.go) $(MAKEFILE_LIST) - sed -En 's,^type (\S+) .* // (.*=.*),\1 \2,p' $(filter btrfsitem/item_%.go,$^) | while read -r typ keys; do for key in $$keys; do echo "$$key" "$$typ"; done; done >$@ + sed -En 's,^type (\S+) .* // (.*=.*),\1 \2,p' $(sort $(filter btrfsitem/item_%.go,$^)) | while read -r typ keys; do for key in $$keys; do echo "$$key" "$$typ"; done; done >$@ files += btrfsitem/items.txt -btrfsitem/items.go: btrfsitem/items.txt $(MAKEFILE_LIST) +btrfsitem/items_gen.go: btrfsitem/items.txt $(MAKEFILE_LIST) { \ echo 'package $(@D)'; \ echo 'import "lukeshu.com/btrfs-tools/pkg/btrfs/internal"'; \ - echo 'type Type = internal.ItemType'; \ echo 'const ('; \ sed -E 's,(.*)=(.*) (.*),\1_KEY=internal.\1_KEY,' $<; \ echo ')'; \ + sed -E 's,(.*)=(.*) (.*),\3,' $< | LC_COLLATE=C sort -u | sed 's,.*,func (&) isItem() {},'; \ } | gofmt >$@ -files += btrfsitem/items.go +files += btrfsitem/items_gen.go internal/itemtype.go: btrfsitem/items.txt $(MAKEFILE_LIST) { \ diff --git a/pkg/btrfs/btrfsitem/items.go b/pkg/btrfs/btrfsitem/items.go index e9e03b8..51e6344 100644 --- a/pkg/btrfs/btrfsitem/items.go +++ b/pkg/btrfs/btrfsitem/items.go @@ -1,20 +1,11 @@ package btrfsitem -import "lukeshu.com/btrfs-tools/pkg/btrfs/internal" +import ( + "lukeshu.com/btrfs-tools/pkg/btrfs/internal" +) type Type = internal.ItemType -const ( - CHUNK_ITEM_KEY = internal.CHUNK_ITEM_KEY - DEV_ITEM_KEY = internal.DEV_ITEM_KEY - DEV_EXTENT_KEY = internal.DEV_EXTENT_KEY - UNTYPED_KEY = internal.UNTYPED_KEY - QGROUP_RELATION_KEY = internal.QGROUP_RELATION_KEY - INODE_ITEM_KEY = internal.INODE_ITEM_KEY - INODE_REF_KEY = internal.INODE_REF_KEY - ORPHAN_ITEM_KEY = internal.ORPHAN_ITEM_KEY - PERSISTENT_ITEM_KEY = internal.PERSISTENT_ITEM_KEY - ROOT_ITEM_KEY = internal.ROOT_ITEM_KEY - UUID_SUBVOL_KEY = internal.UUID_SUBVOL_KEY - UUID_RECEIVED_SUBVOL_KEY = internal.UUID_RECEIVED_SUBVOL_KEY -) +type Item interface { + isItem() +} diff --git a/pkg/btrfs/btrfsitem/items_gen.go b/pkg/btrfs/btrfsitem/items_gen.go new file mode 100644 index 0000000..5234c96 --- /dev/null +++ b/pkg/btrfs/btrfsitem/items_gen.go @@ -0,0 +1,29 @@ +package btrfsitem + +import "lukeshu.com/btrfs-tools/pkg/btrfs/internal" + +const ( + CHUNK_ITEM_KEY = internal.CHUNK_ITEM_KEY + DEV_ITEM_KEY = internal.DEV_ITEM_KEY + DEV_EXTENT_KEY = internal.DEV_EXTENT_KEY + UNTYPED_KEY = internal.UNTYPED_KEY + QGROUP_RELATION_KEY = internal.QGROUP_RELATION_KEY + INODE_ITEM_KEY = internal.INODE_ITEM_KEY + INODE_REF_KEY = internal.INODE_REF_KEY + ORPHAN_ITEM_KEY = internal.ORPHAN_ITEM_KEY + PERSISTENT_ITEM_KEY = internal.PERSISTENT_ITEM_KEY + ROOT_ITEM_KEY = internal.ROOT_ITEM_KEY + UUID_SUBVOL_KEY = internal.UUID_SUBVOL_KEY + UUID_RECEIVED_SUBVOL_KEY = internal.UUID_RECEIVED_SUBVOL_KEY +) + +func (Chunk) isItem() {} +func (Dev) isItem() {} +func (DevExtent) isItem() {} +func (DevStats) isItem() {} +func (Empty) isItem() {} +func (Inode) isItem() {} +func (InodeRef) isItem() {} +func (Orphan) isItem() {} +func (Root) isItem() {} +func (UUIDMap) isItem() {} |