From f60d112f308eacd883cc37b2b5fa739c74b37f68 Mon Sep 17 00:00:00 2001 From: RobertDober Date: Sun, 11 Apr 2021 13:00:41 +0200 Subject: [PATCH 1/2] That should work --- .github/workflows/ci.yml | 4 ++-- README.md | 39 ++++++++++++++++++++++++++------------- README.md.eex | 6 +++--- lib/extractly.ex | 37 ++++++++++++++++++++++++++----------- mix.exs | 3 ++- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9d98a8..b023332 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,12 +11,12 @@ on: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} strategy: matrix: otp: ['21.3', '22.2', '23.0', '23.1.4'] - elixir: ['1.10.0', '1.10.3', '1.11.1', '1.11.2'] + elixir: ['1.10.0', '1.10.3', '1.11.1', '1.11.2', '1.11.3'] steps: - uses: actions/checkout@v2 - uses: actions/setup-elixir@v1 diff --git a/README.md b/README.md index 9f55b52..5d8bb01 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ It has been generated from the template `README.md.eex` by Extractly (https://gi and any changes you make in this file will most likely be lost --> -![CI](https://github.com/RobertDober/extractly/workflows/CI/badge.svg) +[![CI](https://github.com/RobertDober/extractly/workflows/CI/badge.svg)](https://github.com/RobertDober/extractly/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/RobertDober/extractly/badge.svg?branch=master)](https://coveralls.io/github/RobertDober/extractly?branch=master) [![Hex.pm](https://img.shields.io/hexpm/v/extractly.svg)](https://hex.pm/packages/extractly) [![Hex.pm](https://img.shields.io/hexpm/dw/extractly.svg)](https://hex.pm/packages/extractly) @@ -80,7 +80,7 @@ and any changes you make in this file will most likely be lost Returns docstring of a function (or nil) Ex: - iex(1)> Extractly.functiondoc("Extractly.moduledoc/1") + iex(0)> Extractly.functiondoc("Extractly.moduledoc/1") [ " Returns docstring of a module (or nil)", " Ex:", "", @@ -90,10 +90,10 @@ and any changes you make in this file will most likely be lost We can also pass a list of functions to get their docs concatenated - iex(2)> out = Extractly.functiondoc(["Extractly.moduledoc/1", "Extactly.functiondoc/2"]) - ...(2)> # as we are inside the docstring we required we would need a quine to check for the - ...(2)> # output, let us simplify - ...(2)> String.split(out, "\n") |> Enum.take(5) + iex(1)> out = Extractly.functiondoc(["Extractly.moduledoc/1", "Extactly.functiondoc/2"]) + ...(1)> # as we are inside the docstring we required we would need a quine to check for the + ...(1)> # output, let us simplify + ...(1)> String.split(out, "\n") |> Enum.take(5) [ " Returns docstring of a module (or nil)", " Ex:", "", @@ -102,23 +102,23 @@ and any changes you make in this file will most likely be lost If all the functions are in the same module the following form can be used - iex(3)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly") - ...(3)> String.split(out, "\n") |> hd() + iex(2)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly") + ...(2)> String.split(out, "\n") |> hd() " Returns docstring of a module (or nil)" However it is convenient to add a markdown headline before each functiondoc, especially in these cases, it can be done by indicating the `headline: level` option - iex(4)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly", headline: 2) - ...(4)> String.split(out, "\n") |> Enum.take(3) + iex(3)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly", headline: 2) + ...(3)> String.split(out, "\n") |> Enum.take(3) [ "## Extractly.moduledoc/1", "", " Returns docstring of a module (or nil)"] Often times we are interested by **all** public functiondocs... - iex(5)> out = Extractly.functiondoc(:all, module: "Extractly", headline: 2) - ...(5)> String.split(out, "\n") |> Enum.take(3) + iex(4)> out = Extractly.functiondoc(:all, module: "Extractly", headline: 2) + ...(4)> String.split(out, "\n") |> Enum.take(3) [ "## Extractly.do_not_edit_warning/1", "", " Emits a comment including a message not to edit the created file, as it will be recreated from this template."] @@ -128,6 +128,19 @@ and any changes you make in this file will most likely be lost Returns docstring of a macro (or nil) Same naming convention for macros as for functions. +### Extractly.task/2 + +Returns the output of a mix task + Ex: + + iex(5)> Extractly.task("cmd", ~W[echo 42]) + "42\n" + + iex(6)> Extractly.task("no-such-mix-task") |> String.replace(~r{\n.*}, "") + "***Error, the following output was produced wih error code 1" + + iex(7)> Extractly.task("cmd", ~W[no-such-shell-cmd]) + "***Error, the following output was produced wih error code 1\nsh: no-such-shell-cmd: command not found\n" ## Installation @@ -138,7 +151,7 @@ by adding `extractly` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:extractly, "~> 0.2.0"} + {:extractly, "~> 0.3.0"} ] end ``` diff --git a/README.md.eex b/README.md.eex index 35f3a0e..e9b3919 100644 --- a/README.md.eex +++ b/README.md.eex @@ -2,7 +2,7 @@ <%= xtra.do_not_edit_warning template: template %> -![CI](https://github.com/RobertDober/extractly/workflows/CI/badge.svg) +[![CI](https://github.com/RobertDober/extractly/workflows/CI/badge.svg)](https://github.com/RobertDober/extractly/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/RobertDober/extractly/badge.svg?branch=master)](https://coveralls.io/github/RobertDober/extractly?branch=master) [![Hex.pm](https://img.shields.io/hexpm/v/extractly.svg)](https://hex.pm/packages/extractly) [![Hex.pm](https://img.shields.io/hexpm/dw/extractly.svg)](https://hex.pm/packages/extractly) @@ -16,7 +16,7 @@ ### API -<%= xtra.functiondoc ["moduledoc/1", "functiondoc/2", "macrodoc/1"], module: "Extractly", headline: 3 %> +<%= xtra.functiondoc ["moduledoc/1", "functiondoc/2", "macrodoc/1", "task/2"], module: "Extractly", headline: 3 %> ## Installation @@ -38,7 +38,7 @@ be found at [https://hexdocs.pm/extractly](https://hexdocs.pm/extractly). ## Author -Copyright © 2018,9, 2020,1 Robert Dober, robert.dober@gmail.com, +Copyright © 20[18-21] Robert Dober, robert.dober@gmail.com, # LICENSE diff --git a/lib/extractly.ex b/lib/extractly.ex index 6e3dfed..c429d8b 100644 --- a/lib/extractly.ex +++ b/lib/extractly.ex @@ -35,7 +35,7 @@ defmodule Extractly do Returns docstring of a function (or nil) Ex: - iex(1)> Extractly.functiondoc("Extractly.moduledoc/1") + iex(0)> Extractly.functiondoc("Extractly.moduledoc/1") [ " Returns docstring of a module (or nil)", " Ex:", "", @@ -45,10 +45,10 @@ defmodule Extractly do We can also pass a list of functions to get their docs concatenated - iex(2)> out = Extractly.functiondoc(["Extractly.moduledoc/1", "Extactly.functiondoc/2"]) - ...(2)> # as we are inside the docstring we required we would need a quine to check for the - ...(2)> # output, let us simplify - ...(2)> String.split(out, "\\n") |> Enum.take(5) + iex(1)> out = Extractly.functiondoc(["Extractly.moduledoc/1", "Extactly.functiondoc/2"]) + ...(1)> # as we are inside the docstring we required we would need a quine to check for the + ...(1)> # output, let us simplify + ...(1)> String.split(out, "\\n") |> Enum.take(5) [ " Returns docstring of a module (or nil)", " Ex:", "", @@ -57,23 +57,23 @@ defmodule Extractly do If all the functions are in the same module the following form can be used - iex(3)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly") - ...(3)> String.split(out, "\\n") |> hd() + iex(2)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly") + ...(2)> String.split(out, "\\n") |> hd() " Returns docstring of a module (or nil)" However it is convenient to add a markdown headline before each functiondoc, especially in these cases, it can be done by indicating the `headline: level` option - iex(4)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly", headline: 2) - ...(4)> String.split(out, "\\n") |> Enum.take(3) + iex(3)> out = Extractly.functiondoc(["moduledoc/1", "functiondoc/2"], module: "Extractly", headline: 2) + ...(3)> String.split(out, "\\n") |> Enum.take(3) [ "## Extractly.moduledoc/1", "", " Returns docstring of a module (or nil)"] Often times we are interested by **all** public functiondocs... - iex(5)> out = Extractly.functiondoc(:all, module: "Extractly", headline: 2) - ...(5)> String.split(out, "\\n") |> Enum.take(3) + iex(4)> out = Extractly.functiondoc(:all, module: "Extractly", headline: 2) + ...(4)> String.split(out, "\\n") |> Enum.take(3) [ "## Extractly.do_not_edit_warning/1", "", " Emits a comment including a message not to edit the created file, as it will be recreated from this template."] @@ -134,6 +134,21 @@ defmodule Extractly do end end + @doc """ + Returns the output of a mix task + Ex: + + iex(5)> Extractly.task("cmd", ~W[echo 42]) + "42\\n" + """ + def task(task, args \\ []) + def task(task, args) do + case System.cmd("mix", [task | args]) do + {output, 0} -> output + {output, error} -> "***Error, the following output was produced wih error code #{error}\n#{output}" + end + end + @doc false def version do :application.ensure_started(:extractly) diff --git a/mix.exs b/mix.exs index e95c7c6..98f2849 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Extractly.MixProject do use Mix.Project - @version "0.2.0" + @version "0.3.0" @url "https://github.com/robertdober/extractly" @description """ @@ -96,3 +96,4 @@ defmodule Extractly.MixProject do end end +# SPDX-License-Identifier: Apache-2.0 From 34770c9334402056e6ce40d553a19ea508a3c70c Mon Sep 17 00:00:00 2001 From: RobertDober Date: Sun, 11 Apr 2021 13:09:32 +0200 Subject: [PATCH 2/2] removed obsolete travis.yml --- .travis.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 07031d5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: elixir -sudo: false - -branches: - only: - - master - - development - -elixir: - - 1.9.0 - - 1.9.1 -otp_release: - - 21.0 - - 22.0 - - 22.0.7 - -matrix: - include: - - elixir: 1.7.0 - otp_release: 20.3 - - elixir: 1.7.3 - otp_release: 20.3 - - elixir: 1.8.2 - otp_release: 21.2.4 - - elixir: 1.9.0 - otp_release: 21.1 - - elixir: 1.9.1 - otp_release: 21.3 - -env: - - MIX_ENV=test - -script: mix coveralls.travis