We can use AppleScript to toggle between dark and light mode under macOS.

-- Toggle dark mode
tell application "System Events"
    tell appearance preferences
        get properties
        if dark mode is false then
            set dark mode to true
            set dark mode to false
        end if
    end tell
end tell

Save this in a file say, toggle-dark-mode.applescript. Now we can use osascript to run this.

osascript ~/bin/toggle-dark-mode.applescript