Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First shot at issue #8 #9

Merged
merged 2 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:",
"",
Expand All @@ -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:",
"",
Expand All @@ -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."]
Expand All @@ -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
Expand All @@ -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
```
Expand Down
6 changes: 3 additions & 3 deletions README.md.eex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -38,7 +38,7 @@ be found at [https://hexdocs.pm/extractly](https://hexdocs.pm/extractly).

## Author

Copyright © 2018,9, 2020,1 Robert Dober, [email protected],
Copyright © 20[18-21] Robert Dober, [email protected],

# LICENSE

Expand Down
37 changes: 26 additions & 11 deletions lib/extractly.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
"",
Expand All @@ -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:",
"",
Expand All @@ -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."]
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -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 """
Expand Down Expand Up @@ -96,3 +96,4 @@ defmodule Extractly.MixProject do
end

end
# SPDX-License-Identifier: Apache-2.0