Giter Site home page Giter Site logo

khusnetdinov / loki Goto Github PK

View Code? Open in Web Editor NEW
87.0 4.0 7.0 73 KB

:pencil: Loki is library that includes helpers for building powerful interactive command line applications, tasks, modules.

License: MIT License

Elixir 100.00%
loki elixir-lang elixir-phoenix elixir-library elixir

loki's Introduction

Loki Code Triagers Badge Build Status Hex.pm Ebert

Loki is a toolkit for building powerful command-line interfaces.

img

Example

img

Instalation

Add loki to your list of dependencies in mix.exs:

def deps do
  [{:loki, "~> 1.2.2"}]
end

Usage

Import all or desired module to scope:

defmodule Project do
  # Import all modules
  use Loki

  # Or import single modules
  import Loki.Shell
  import Loki.Cmd
  import Loki.Directory
  import Loki.File
  import Loki.FileManipulation

  ...

end

Modules

Loki.Shell

Helpers for interaction with user and printing message to shell.

  • ask/2 - Ask user input with given message. Returns tuple with parsed options.
  • yes?/1 - Ask about positive user input with given message.
  • no?/1 - Ask about negative user input with given message.
  • say/1 - Printing message to shell.
  • say_create/1 - Printing message about create file to shell.
  • say_force/1 - Printing message about force action to shell.
  • say_identical/1 - Printing message about identical files content to shell.
  • say_skip/1 - Printing message about skipping action to shell.
  • say_error/1 - Printing message about to shell.
  • say_conflict/1 - Printing message about conflict to shell.
  • say_exists/1 - Printing message about existance to shell.
  • say_rename/2 - Printing message about rename files to shell.
  • say_copy/2 - Printing message about copy files to shell.
  • say_remove/1 - Printing message about removing file to shell.

Loki.Cmd

Executing terminal commands helpers.

  • execute/1 - Execute shell command with Env variables as options.
  • execute_in_path/2 - Execute shell command with Env variables as options in given path.
  • format_output/1 - Format execution output for reading in shell.

Loki.Directory

Working with folders helpers.

  • create_directory/1 - Helper for create directory.
  • exists_directory?/1 - Helper for checking if file exists.
  • copy_directory/2 - Helper for copy directory.
  • remove_directory/1 - Helper for remove directory.

Loki.File

Helpers for working with file.

  • create_file/1 - Helper for create file.
  • create_file_force/1 - Helper for create file in force mode.
  • exists_file?/1 - Helper check if file exists.
  • identical_file?/2 - Helper check if file identical.
  • copy_file/2 - Helper for copy files.
  • create_link/2 - Helper for create link.
  • remove_file/1 - Helper for remove file.
  • rename/2 - Helper for rename files and dirs.

Loki.FileManipulation

Helpers for content manipulation injecting, appending, and other.

  • append_to_file/2 - Helper appends lines to file.
  • prepend_to_file/2 - Helper prepends lines to file.
  • remove_from_file/2 - Helper removes lines from file.
  • inject_into_file/3 - Helper injecting lines to file with before and after options.
  • replace_in_file/3 - Helper replaces lines in file.
  • comment_in_file/2 - Helper comments line in file.
  • uncomment_in_file/2 - Helper uncomments lines in file.
  • remove_comments_in_file - Helper removes all comments in file.

Documentation

Read hexdocs.pm

Contribution

Clone repo, implement additional helpers, write tests and PR welcome!

License

The gem is available as open source under the terms of the MIT License.

loki's People

Contributors

jfpedroza avatar khusnetdinov avatar ktec avatar selvaticus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

loki's Issues

Depfu Error: No dependency files found

Hello,

We've tried to activate or update your repository on Depfu and couldn't find any supported dependency files. If we were to guess, we would say that this is not actually a project Depfu supports and has probably been activated by error.

Monorepos

Please note that Depfu currently only searches for your dependency files in the root folder. We do support monorepos and non-root files, but don't auto-detect them. If that's the case with this repo, please send us a quick email with the folder you want Depfu to work on and we'll set it up right away!

How to deactivate the project

  • Go to the Settings page of either your own account or the organization you've used
  • Go to "Installed Integrations"
  • Click the "Configure" button on the Depfu integration
  • Remove this repo (khusnetdinov/loki) from the list of accessible repos.

Please note that using the "All Repositories" setting doesn't make a lot of sense with Depfu.

If you think that this is a mistake

Please let us know by sending an email to [email protected].


This is an automated issue by Depfu. You're getting it because someone configured Depfu to automatically update dependencies on this project.

Possible bug on the Shell.say code

Hi,

While working on the issue 35, I came across what I think its a bug on the Shell.say function.

This is the function definition:

  @spec say(String.t) :: none()
  def say(message) when is_input(message), do: say(message, [])

  @spec say(any) :: none()
  def say(_any), do: raise ArgumentError, message: "Invalid argument, accept String or List!"

  @spec say(String.t, Keyword.t) :: none()
  def say(message, opts) do
    case Keyword.get(opts, :silent) do
      nil ->
        IO.puts message
      true ->
        nil
    end
  end

I assume the is_input guard will be completely bypassed if the function is called with 2 parameter as the third definition will match anything with 2 parameters def say(message, opts) hence is possible to call the Shell.say with types other than String or List

Does this sound correct or am I missing something obvious?

Cheers

OptionParser requires passing the :switches or :strict option

OptionParser now requires passing the :switches or :strict option, otherwise it throws a warning everytime it's used. I would like to ask: What is the purpose of using OptionParser to parse the input from ask and the other functions from Loki.Shell?

This is what I get when I run the tests (in 6 of them):

...warning: not passing the :switches or :strict option to OptionParser is deprecated
  (elixir) lib/option_parser.ex:562: OptionParser.build_config/1
  (elixir) lib/option_parser.ex:197: OptionParser.parse/2
  test/loki/shell_test.exs:11: anonymous fn/0 in Loki.ShellTest."test Shell #ask input"/1
  (ex_unit) lib/ex_unit/capture_io.ex:150: ExUnit.CaptureIO.do_capture_io/2
  (ex_unit) lib/ex_unit/capture_io.ex:120: ExUnit.CaptureIO.do_capture_io/3
  test/loki/shell_test.exs:10: Loki.ShellTest."test Shell #ask input"/1
  (ex_unit) lib/ex_unit/runner.ex:312: ExUnit.Runner.exec_test/1
  (stdlib) timer.erl:166: :timer.tc/1
  (ex_unit) lib/ex_unit/runner.ex:251: anonymous fn/4 in ExUnit.Runner.spawn_test/3

Shell.ask always returns downcase

When asking the user for case sensitive IDs, Loki automatically runs a format with String.downcase. It would be great if we could pass the option to to_lower the answer with a default of not running a to_lower.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.