commit dd1562c064ef82c610805dfd8cdaca5af54f6d22
parent f5fde32e94d77a44e85a28f9263531b34fdf7c8b
Author: Oliver Lowe <o@olowe.co>
Date: Wed, 19 Jan 2022 00:37:18 +1100
Always format generated code
While here document what is needed to actually run go generate.
Diffstat:
4 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
@@ -56,6 +56,12 @@ Source code for the basic lookup, create and delete operations of some
Icinga2 object types, such as Host and Service, are generated
automatically.
+To generate the code, ensure the following tools are available:
+
+* POSIX shell (/bin/sh)
+* awk
+* gofmt
+
The shell script crud.sh writes Go source code by reading a template
file and doing some text substitution. It loops through object types,
piping the template file crud.skel into the awk script crud.awk for
diff --git a/crud.go b/crud.go
@@ -55,7 +55,6 @@ func (c *Client) DeleteHost(name string, cascade bool) error {
}
return nil
}
-
// Services returns a slice of Service matching the filter expression filter.
// If no services match, error wraps ErrNoMatch.
// To fetch all service, set filter to the empty string ("").
@@ -107,7 +106,6 @@ func (c *Client) DeleteService(name string, cascade bool) error {
}
return nil
}
-
// Users returns a slice of User matching the filter expression filter.
// If no users match, error wraps ErrNoMatch.
// To fetch all user, set filter to the empty string ("").
@@ -159,7 +157,6 @@ func (c *Client) DeleteUser(name string, cascade bool) error {
}
return nil
}
-
// HostGroups returns a slice of HostGroup matching the filter expression filter.
// If no hostgroups match, error wraps ErrNoMatch.
// To fetch all hostgroup, set filter to the empty string ("").
diff --git a/crud.sh b/crud.sh
@@ -27,7 +27,6 @@ do
esac
done
-
if test -n "$file"
then
echo "$head" > "$file"
@@ -39,8 +38,8 @@ for t in $types
do
if test -n "$file"
then
- awk -v "type=$t" -f crud.awk crud.skel >> "$file"
+ awk -v "type=$t" -f crud.awk crud.skel | gofmt >> "$file"
else
- awk -v "type=$t" -f crud.awk crud.skel
+ awk -v "type=$t" -f crud.awk crud.skel | gofmt
fi
done
diff --git a/crud.skel b/crud.skel
@@ -44,7 +44,7 @@ func (c *Client) CreateTYPE(LOWER TYPE) error {
// depending on the TYPE are also deleted. If no TYPE is found, error wraps
// ErrNotExist.
func (c *Client) DeleteTYPE(name string, cascade bool) error {
- if err := c.deleteObject("/objects/PLURAL/" + name, cascade); err != nil {
+ if err := c.deleteObject("/objects/PLURAL/"+name, cascade); err != nil {
return fmt.Errorf("delete LOWER %s: %w", name, err)
}
return nil