New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas for a nicer way to support different os's/implementation in types #512

Open
asteven opened this Issue Jan 12, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@asteven
Contributor

asteven commented Jan 12, 2017

Just thinking out loud.

Instead of the endless case esac if os then else what if a type would have a internal API?
Maybe in form of shell functions?
Then there could be a default implementation, e.g. in __some_type/lib/default
And if some $os doesn't like that it can create it's own implementation in _some_type/lib/$os

The gencode-* would then just call shell functions which write to stdout.
e.g.

_some_type/lib/default:

_add_user() {
   printf 'gpasswd -a "%s" "%s"\n' "$1" "$2"
}

_remove_user() {
   printf 'gpasswd -d "%s" "%s"\n' "$1" "$2"
}

_some_type/lib/netbsd:

_add_user() {
   printf 'usermod -G "%s" "%s"\n' "$1" "$2"
}

_remove_user() {
   printf 'usermod ;;# "%s" "%s"\n' "$1" "$2"
}

_some_type/gencode-remote:

. "$__type/lib/default"
if [ -f "$__type/lib/$os" ]; then
   . "$__type/lib/$os"
fi
...

case "$state_should" in
   present)
      for group in $(comm -13 "$__object/explorer/group" "$__object/files/group.sorted"); do
         _add_user "$group" "$user"
      done
   ;;
   absent)
      for group in $(comm -12 "$__object/explorer/group" "$__object/files/group.sorted"); do
         _remove_user "$group" "$user"
      done
   ;;
esac

One could even implement kind of 'call super' using an aproach like this.

No more stinking spagetti code.
Comments?

@telmich

This comment has been minimized.

Contributor

telmich commented Jan 14, 2017

Great idea! But I suggest using $__type/files/lib instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment