Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/lua5.2
- --
- --
- package.path = package.path .. ";lua/?.lua"
- local lfunc = require "luaFunctional"
- lfunc.loadglobally(lfunc)
- --
- --
- VERSION = "0.1b"
- NAME = "multiBox"
- DESC = [[
- Manager for multiple dropBox accounts on the same machine
- ]]
- LICENSE = "GNU General Public License"
- USAGE = string.format([[
- Usage: %s [account_name account_command | command]
- account_name :: Profile name for any of the multiple accounts defined.
- account_commands
- start :: Starts dropbox for this account
- stop :: Stops dropbox for this account
- delete :: Deletes account profile
- status :: Gets status for this account
- command
- version :: Shows current version
- help :: Shows this help
- accounts :: Lists all profiles avaible in the system
- %s
- This software comes without any warranty. Use at your own risk.
- If you like it, or you want to contribute with it, please give feedback.
- ]], NAME, LICENSE)
- --
- function usage(ss)
- return function ()
- print(USAGE)
- end
- end
- function status(account)
- return function ()
- print("Status")
- end
- end
- function start(account)
- return function ()
- print("Starting " .. account)
- end
- end
- function stop(account)
- return function ()
- print("Stoping DropBox account " .. account)
- end
- end
- function accounts()
- return function ()
- print("Listing accounts")
- end
- end
- function version()
- return function ()
- print(string.format("%s %s [%s]\n\n%s", NAME, VERSION, LICENSE, DESC))
- end
- end
- eq1 = curry(eq,2)
- function prepareCommand(tuple)
- local eqCurry = curry(eq,2)
- local eqCommand = function (cmd)
- return function (t)
- return eq1(cmd)(t)
- end
- end
- getComplexCommand = function (t)
- return casef(
- {eqCommand("start"), start},
- {eqCommand("stop"), stop},
- {eqCommand("status"), status},
- {eqCommand("delete"), function() print("DELETE not defined") end},
- {1, usage})(t[1])
- end
- getSimpleCommand = function (a)
- return casef(
- {eqCommand("accounts"), accounts},
- {eqCommand("version"), version},
- {1, usage})(a)
- end
- return casef(
- {function(t) return type(t) == "table" end, getComplexCommand},
- {true, getSimpleCommand})(tuple)
- end
- function prepareAccount (argv)
- local account = table.head(argv)
- local toTuple = function (a) return a, account end
- return maptup(toTuple, table.tail(argv))
- end
- function main(argc, argv)
- mapCurry = curry(map,2)
- lenEq = curry(function(n, t1) return n == #t1 end, 2)
- lenGt = curry(function(n, t1) return n < #t1 end, 2)
- lenLt = curry(function(m, t1) return n > #t1 end, 2)
- return casef(
- {lenGt(1), compose(mapCurry(prepareCommand), prepareAccount)},
- {lenEq(1), mapCurry(prepareCommand)},
- {1 , {usage()}})(argv)
- end
- local a = main(#arg, arg)
- for _,v in ipairs(a) do print(v()) end
Advertisement
Add Comment
Please, Sign In to add comment