First, compile the interpreter with the Nit compiler/interpreter, and launch the program on a brainfuck source file for interpretation.
Example:
-~~~
+~~~sh
nitc ./brainfuck.nit
./brainfuck ./examples/hello.bf
~~~
import github::github_curl
import template
-import opts
+import config
redef class Object
# Factorize cast
var opt_keepgoing = new OptionBool("Skip merge conflicts", "-k", "--keep-going")
var opt_all = new OptionBool("Merge all", "-a", "--all")
var opt_status = new OptionArray("A status context that must be \"success\" (e.g. default)", "--status")
-var opts = new OptionContext
-opts.add_option(opt_repo, opt_auth, opt_query, opt_status, opt_all, opt_keepgoing)
-opts.parse(sys.args)
-var args = opts.rest
+var usage = new Buffer
+usage.append "Usage: github_merge [OPTION]... <PR number...>\n"
+usage.append "Query the Github PR API to perform a merge."
+
+var config = new Config
+config.tool_description = usage.write_to_string
+config.add_option(opt_repo, opt_auth, opt_query, opt_status, opt_all, opt_keepgoing)
+
+config.parse_options(sys.args)
+
+if config.opt_help.value then
+ config.usage
+ exit 0
+end
+
+var args = config.args
var auth = opt_auth.value or else ""
if auth == "" then auth = get_github_oauth
print "The merge is made"
mergemsg.write_to(stdout)
end
-
maintainer=Jean Privat <jean@pryen.org>
license=Apache-2.0
[upstream]
-browse=https://github.com/nitlang/nit/tree/master/contrib/github_merge.nit
+browse=https://github.com/nitlang/nit/tree/master/contrib/github_merge/
git=https://github.com/nitlang/nit.git
-git.directory=contrib/github_merge.nit
+git.directory=contrib/github_merge/
homepage=http://nitlanguage.org
issues=https://github.com/nitlang/nit/issues
### Dynamic importation
-~~~
+~~~raw
-->print([0..10[.to_a.to_json)
1,20--26: Error: method `to_json` does not exists in `Array[Int]`.
print([0..10[.to_a.to_json)
import wiki_html
import markdown_highlight
+import config
# Locate nit directory
private fun compute_nit_dir(opt_nit_dir: OptionString): String do
return res.file_exists and "{res}/src/nit.nit".file_exists
end
-var opt_help = new OptionBool("Display this help message", "-h", "--help")
var opt_verbose = new OptionCount("Verbose level", "-v")
var opt_config = new OptionString("Path to config.ini file", "-c", "--config")
var opt_init = new OptionBool("Initialize a new wiki in the current directory", "--init")
var opt_fetch = new OptionBool("Render local source from git repo", "--fetch")
var opt_nit_dir = new OptionString("Nit base directory", "--nit-dir")
-var context = new OptionContext
-context.add_option(opt_help, opt_verbose, opt_config)
-context.add_option(opt_init, opt_status, opt_render, opt_force)
-context.add_option(opt_clean, opt_rsync, opt_fetch, opt_nit_dir)
-context.parse(args)
+var config = new Config
+config.add_option(opt_verbose, opt_config)
+config.add_option(opt_init, opt_status, opt_render, opt_force)
+config.add_option(opt_clean, opt_rsync, opt_fetch, opt_nit_dir)
-var config_filename = "config.ini"
+var usage = new Buffer
+usage.append "Usage: nitiwiki [OPTION]...\n"
+usage.append "A wiki engine based on markdown files and git."
+config.tool_description = usage.write_to_string
+
+config.parse_options(args)
-# --help
-if opt_help.value then
- context.usage
+if config.opt_help.value then
+ config.usage
exit 0
end
+var config_filename = "config.ini"
+
# --init
if opt_init.value then
if config_filename.file_exists then
exit 0
end
-var config = new WikiConfig(config_file)
-var wiki = new Nitiwiki(config)
+var wiki_config = new WikiConfig(config_file)
+var wiki = new Nitiwiki(wiki_config)
# --verbose
wiki.verbose_level = opt_verbose.value
module wiki_base
import template::macro
-import opts
import ini
# A Nitiwiki instance.
import nitcorn
import markdown
import md5
+import config
intrude import wiki_html
end
end
-var config_file_path = "config.ini"
-var iface = "localhost:8080"
-var password_file_path = "passwords"
+var opt_config = new OptionString("Path to config.ini file", "-c", "--config")
+var opt_host = new OptionString("Host to bind the server to", "--host")
+var opt_port = new OptionInt("Port to bind the server to", 8000, "--port")
+var opt_pass = new OptionString("Password file path", "--pass")
+
+var config = new Config
+config.add_option(opt_config, opt_host, opt_port, opt_pass)
+
+var usage = new Buffer
+usage.append "Usage: wiki_edit [OPTION]...\n"
+usage.append "Web server to server generated files and modify the wiki from a web form."
+config.tool_description = usage.write_to_string
+
+config.parse_options(args)
+
+if config.opt_help.value then
+ config.usage
+ exit 0
+end
+
+var config_file_path = opt_config.value or else "config.ini"
+var iface = "{opt_host.value or else "localhost"}:{opt_port.value}"
+var password_file_path = opt_pass.value or else "passwords"
# Load passwords for file
var passwords = if password_file_path.file_exists then
If you need more than one configuration, let's say to sort videos, you can use Nit class refinement. Create a separate Nit module next to `src/sort_downloads.nit` named `sort_videos.nit` and use something like:
- #!/usr/bin/env nit
+~~~nitish
+#!/usr/bin/env nit
- import sort_downloads
+import sort_downloads
- redef class Config
- redef fun source_dir do return "/media/new-drive/video-downloads"
- redef fun dest_dir do return "/media/new-drive/Videos"
- redef fun regex_source_dirs do return ["~/Videos", dest_dir]
- redef fun elapsed_days do return 0
- end
+redef class Config
+ redef fun source_dir do return "/media/new-drive/video-downloads"
+ redef fun dest_dir do return "/media/new-drive/Videos"
+ redef fun regex_source_dirs do return ["~/Videos", dest_dir]
+ redef fun elapsed_days do return 0
+end
- super # this executes the program
+super # this executes the program
+~~~
## Sort only older files