At some point I thought I had understood what the OP wanted and edited the question to reflect that understanding, but the OP demurred and changed it back a bit, so I don't know if this will answer his current question. It is really an answer to the previous form of the question after my edit, but I still think there is a chance that this is really what the OP is after.
The basic idea is that we want a function that handles its argument exactly the way a minor mode does, so we figure out what a "real" minor mode function does and strip way all the minor mode paraphernalia, leaving only the argument handling. But the argument is supposed to enable or disable something, so we emulate this enabling/disabling by defining a variable and set it to
t to "enable" or to
nil to "disable" whatever it is we are enabling or disabling. For a "real" minor mode, the variable is a buffer-local variable with the same name as the mode function (e.g.
abbrev-mode is the name of the mode function and also the name of the mode variable), so we follow that convention.
With that as explanation, here's a minimal function that handles its argument the way the quoted paragraph in the question describes and "enables"/"disables" whatever it is we are trying to enable/disable by setting the corresponding variable. Here's the minimal code:
(defvar-local foo-bar nil)
(defun foo-bar (&optional arg)
((eq arg 'toggle) (not foo-bar))
((and (numberp arg) (< arg 1)) nil)
I assume that the variable should be buffer-local here, but it could be made global: just change the
nil, so it is "disabled".
The tests that @antonio describes in his answer can be used to verify that everything is as it should be: after every test, you can evaluate the
foo-bar variable in the appropriate buffer to make sure its value is as expected.
BTW, I did this by macroexpanding a fictitious
(define-minor-mode foo-bar "foo-bar docstring") and ruthlessly eliminating everything but the argument handling and the state variable.
Although I hope this will answer the OP's "real" question, I am not holding my breath. Depending on how it goes, I might keep it, amend it or delete it.