{"id":17623678,"url":"https://github.com/zachgrayio/cmdloop","last_synced_at":"2025-03-30T01:35:21.389Z","repository":{"id":90044291,"uuid":"101470293","full_name":"zachgrayio/cmdloop","owner":"zachgrayio","description":"A lightweight, dependency-free library for building simple, declarative command-line programs in Kotlin","archived":false,"fork":false,"pushed_at":"2017-09-14T20:17:29.000Z","size":77,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T03:37:35.379Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zachgrayio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-26T07:24:59.000Z","updated_at":"2017-08-26T08:11:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"63ee7388-1051-4fc1-af2e-6457fb822dc5","html_url":"https://github.com/zachgrayio/cmdloop","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fcmdloop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fcmdloop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fcmdloop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachgrayio%2Fcmdloop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zachgrayio","download_url":"https://codeload.github.com/zachgrayio/cmdloop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246265117,"owners_count":20749591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-22T21:23:28.621Z","updated_at":"2025-03-30T01:35:21.362Z","avatar_url":"https://github.com/zachgrayio.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cmdloop\n\nA lightweight, dependency-free library for building simple, declarative command-line programs in Kotlin.\n\n### Example program\n\nHere's a CLI calculator implemented on top of cmdloop: [Kalk](https://github.com/zachgrayio/kalk).\n\n### Binaries\n\nFirst add the bintray repo:\n\n```groovy\nrepositories {\n    maven {\n        url  \"https://zachgray.bintray.com/cmdloop\"\n    }\n}\n```\nthen the binary dependency can be added:\n\n```groovy\ndependencies {\n    compile \"io.zachgray.cmdloop:cmdloop:2.0.2\"\n}\n```\n\n### Example program\n\n```kotlin\nfun main(args:Array\u003cString\u003e) {\n    commandLoop {\n        // optional: a custom welcome message\n        welcomeMessage {\n            \"Hi! Enter a mathematical expression to be evaluated, or enter a command.\"\n        }\n\n        // define the command prefix\n        commandPrefix {\n            \"/\" //example: /exit, /time\n        }\n\n        // define a custom command to get the current time\n        command(\"time\") { _, _ -\u003e\n            println(\"  the time is ${Date().asTimeString()}\")\n        }\n\n        // override loop control (continue by default) with break - loop will exit\n        command(\"die\", loopControl = BREAK) { _, _ -\u003e\n            println(\"I'm dead\")\n        }\n\n        // print any args that were passed to the program on launch\n        command(\"args\") { _, _ -\u003e\n            args.forEachIndexed { i, arg -\u003e println(\"arg[$i]=$arg\") }\n        }\n\n        // print command params\n        command(\"printParams\") { params, _ -\u003e\n            println(\"you included params: $params\")\n        }\n\n        // optional: the \"default\" case gets executed when user input is not a command. in this case, the mathematical\n        // expression is evaluated and results printed.\n        default {\n            { input -\u003e\n                input?.let {\n                    val expression = it.toRPNExpression()\n                    println(\"  numbers:   ${expression.numbers}\")\n                    println(\"  operators: ${expression.operators}\")\n                    println(\"  solution:  ${expression.evaluate()}\")\n                }\n            }\n        }\n\n        // optional: catch error\n        catch {\n            { _ -\u003e\n                println(\"  invalid expression, please try again.\")\n            }\n        }\n    }\n}\n```\n\n### Example program output\n\n```\nHi! Enter a message and it will be echoed, or enter a command. Commands:\n  /args\n  /die\n  /exit\n  /getTime\n  /history\n\u003e /getTime\n  the time is 02:39\n\u003e /history\n0 /getTime\n1 /history\n\u003e hello\n  you said \"hello\"\n\u003e /args\n  arg[0]=argh\n\u003e /exit\n  bye! 👋\n```\n\n### Default Commands\n\nOut of the box, the following commands are included:\n- `exit` - exit the program\n- `history` - view command history\n\nTo provide a custom exit function, you could do the following:\n\n```kotlin\ncommand(\"exit\", loopControl = BREAK) {\n    println(\"custom exit!\")\n}\n```\n\n### Build this repository\n`./gradlew assemble` ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachgrayio%2Fcmdloop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzachgrayio%2Fcmdloop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachgrayio%2Fcmdloop/lists"}