Create Command Line Tools
来源:互联网 发布:航信数据维护 编辑:程序博客网 时间:2024/05/13 22:46
使用elixir创建命令行工具,是 http://www.elixirdose.com/post/create_command_line_tools 这个链接的正确完整版
使用mix命令行工具创建新的项目
[root@study elixir]# mix new awesome_cli[root@study elixir]# cd awesome_cli/
修改lib/awesome_cli.ex,内容如下
[root@study awesome_cli]# cat lib/awesome_cli.ex defmodule AwesomeCli do def main(args) do IO.puts "Hello, mirahs!" endend
修改mix.exs,增加escript定义,内容如下
[root@study awesome_cli]# cat mix.exs | grep -v "^.*#"defmodule AwesomeCli.Mixfile do use Mix.Project def project do [app: :awesome_cli, version: "0.0.1", elixir: "~> 1.1-rc", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, escript: escript, deps: deps] end def escript do [main_module: AwesomeCli] end def application do [applications: [:logger]] end defp deps do [] endend
编译后会在当前目录生成awesome_cli可执行文件,运行
[root@study awesome_cli]# mix escript.build[root@study awesome_cli]# ./awesome_cli Hello, mirahs!
下面是完整版本
[root@study awesome_cli]# cat lib/awesome_cli.ex defmodule AwesomeCli do def main(args) do args |> parse_args |> do_process end def parse_args(args) do options = OptionParser.parse(args) case options do {[name: name], _, _} -> [name] {[help: true], _, _} -> :help _ -> :help end end def do_process([name]) do IO.puts "Hello, #{name}! You're awesome!!" end def do_process(:help) do IO.puts """ Usage: ./awesome_clie --name [your name] Options: --help Show this help message. Description: Prints out an awesome message. """ endend
重新编译并运行
[root@study awesome_cli]# mix escript.build[root@study awesome_cli]# ./awesome_cli --name mirahsHello, mirahs! You're awesome!![root@study awesome_cli]# ./awesome_cli --help Usage: ./awesome_clie --name [your name] Options: --help Show this help message. Description: Prints out an awesome message.
项目完整文件
[root@study awesome_cli]# cd ..[root@study elixir]# tree awesome_cli/awesome_cli/├── awesome_cli├── _build│ └── dev│ └── lib│ └── awesome_cli│ └── ebin│ ├── awesome_cli.app│ └── Elixir.AwesomeCli.beam├── config│ └── config.exs├── lib│ └── awesome_cli.ex├── mix.exs├── README.md└── test ├── awesome_cli_test.exs └── test_helper.exs8 directories, 9 files
0 0
- Create Command Line Tools
- Using Python to create UNIX command line tools
- xcode command line tools
- 安装COmmand Line Tools
- Xcode Command Line Tools
- command line tools 安装
- Command Line Tools
- Create database in command-line
- Firebird command Tools line switches
- 安装Xcode Command Line Tools
- Command Line Tools安装方法
- Know How to Use Command-line Tools
- GNU/Linux Command-Line Tools Summary
- mac lion 安装gcc command line tools
- Xcode 5.x添加Command Line Tools
- command line tools工具无法调用
- Xcode Command Line Tools(命令行工具)
- Know How to Use Command-Line Tools
- Peeking Iterator
- CoreText<1>
- C语言指针理解到深入(1)
- Django 通用视图
- Camera(一)使用SurfaceView和Camera类实现拍照
- Create Command Line Tools
- 数据库之创建表&向表中插入数据
- Codeforces #320 Div1 解题报告
- C# web 链接数据库问题二三(一)
- Hadoop 笔记之shuffle详解过程
- "不忍直视"的ViewHolder模式
- dockerfile 创建 ssh 镜像
- 四种Toast的简单代码
- IOS知识点mark