3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

dub 1.0.0 のSingle-file packages

Posted at

dub 1.0.0 Single-file packages

dub 1.0.0の新機能 Single-file packagesを紹介します。
公式のドキュメントはGetting StartedのSingle-file packagesを参照して下さい。

$ dub --version
DUB version 1.0.0, built on Jun 20 2016

Single-file packages

Single-file packagesとは、パッケージレシピファイル(dub.sdl/dub.json)に記述していた内容をソースファイル内に埋め込める機能です。
1つのファイルで構成されるような小さなアプリケーションやスクリプトに対し、dubのサポートを付与することができます。
dubプロジェクトを作成しなくてもdubパッケージを使える点が便利です。

dlang_requests.d
#!/usr/bin/env dub
/+ dub.sdl:
name "dlang_requests"
dependency "requests" version="~>0.1.9"
+/
import std.stdio,
       std.getopt,
       requests;

string url = "http://example.com/";

void main(string[] args)
{
  getopt(args, "url", &url);

  auto rs = Request().get(url);
  writeln(rs.responseBody);
}

dub run --single dlang_requests.d、もしくは行頭にシェバングを追記し実行権限を与えた上で./dlang_requests.dで実行できます。
コマンドラインオプションはdub run --single dlang_requests.d -- --url=http://qiita.comもしくは ./dlang_requests.d --url=http://qiita.comで与えることができます。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?