Git Product home page Git Product logo

hey's Introduction

hey

CircleCI Codacy Badge

During development there are many commands and tools you need to keep track of, with completely different syntaxes between them and sometimes even the same tool has different syntaxes for different operations in the same scope.

Tired of repeatedly looking at sometimes cryptic examples to remember how to do a simple operation while at the end of the day I don't even care about the tool I used to achieve it, I'm starting this pet project to experiment with Scala-native to interface with the different tools, giving them a more sane abstraction level.

The first operations I intend to simplify are to request and change the status of a service running in multiple servers in a non-intrusive manner.

For that, I'll be forwarding calls to Ansible. For comparison, this is an ad-hoc way to get the status and restart some service in a server group using Ansible:

# for the status
ansible someServerGroup -a "systemctl status some-service-name.service"

# for restarting the service
ansible someServerGroup -b -m service -a "name=some-service-name state=restarted"

This is already better than a lot we find in the command line world, but still, hard to remember, full of arguments and not really uniform. What I want is something as easy to remember and uniform as this:

#for the status
hey status -sg someServerGroup -sn some-service-name

# for restarting the service
hey restart -sg someServerGroup -sn some-service-name

Status

Currently, the code is in a very initial, prototype, not really working state. The text here is mostly a mix of stuff currently being experimented with and notes about how I got there, so although they worked for me at some point, there is no guarantee that following the steps would lead to any usable result. Still, I would recommend watching this repo as I expect to have something usable soon :)

  1. Install Ansible: sudo apt install ansible
  2. Add server groups to the /etc/ansible/hosts file:
webservers:
  hosts:
    someHostRange[1:12].some.domain
  1. Install Scala native compilation OS packages (tested with Ubuntu): sudo apt install clang libgc-dev libunwind-dev
  2. We could have an Ansible playbook in the future to install all dependencies but for now, besides the other packages, manual build/install is required for this one: https://github.com/google/re2/wiki/Install
  3. sbt nativeLink
  4. You can use the natively compiled hey tool by calling target/scala-2.11/hey-out

In the future, sbt native packager will be used to produce installation packages so the tool can be used with sudo apt install hey.deb; hey webservers status

Meanwhile, you could do a link to the target and have it available with a proper name from anywhere. For instance:

#if didn't have the ~/bin folder before
cd
mkdir ~/bin
source .profile
#then link the thing
ln -s target/scala-2.11/hey-out ~/bin/hey
#then `cd` into wherever you want and...
hey
Error: at least one of the supported commands should have been called
hey 0.1
Usage: hey [ansible|docker|sbt|git] [options] <args>...

  -vb, --verbosity <value>
                           defaults to full. any other value means silent
Command: ansible [status|restart|stop] [options]
Ansible related commands
  -sg, --serverGroup <value>
                           which servers should I send a command to
  -sn, --serviceName <value>
                           which service should respond to the command
Command: ansible status
Returns the systemd status from those servers
Command: ansible restart
(Re)starts those servers
Command: ansible stop
Stops those servers
Command: docker [bash] [options]
Docker related commands
  -cn, --containerName <value>
                           which container should I execute at
Command: docker bash
Runs bash on the defined containerName
Command: sbt [purge|test] [options] [<suffix>]
Sbt related commands
  -d, --debug              if the process should be started in debug mode
Command: sbt purge
Removes target folders
Command: sbt test
Runs all sbt tests or the ones matching the given suffix
  <suffix>                 This avoids having to use the FQCN, prepending an * to the call
Command: git [squash|checkout] [<targetBranch>] [<targetBranch>]
Git related commands
Command: git squash
Resets index to target branch, allowing all changes to be in a single commit to be done afterwards.
  <targetBranch>           Defaults to master
Command: git checkout
Checks out the given branch name or partial name (if only one match is found)
  <targetBranch>           Defaults to master
You can define default values for command options at the hocon file ~/.hey/hey.conf

Roadmap

Done

  • Useful aliases for ansible, git, sbt and docker
  • Architecture to easy the tool extension
  • Config file for default option and argument values
  • Usage examples

Short term

  • More aliases for supported commands
  • "Summary verbosity"
  • Architecture documentation
  • Publish as dependency / allow private extensions

Middle term

  • Installers
  • Useful aliases for npm, maven, apt, zip, tar, ssh, cron and other common server and developer tools
  • Modularization, so new commands and aliases are realized in external libraries
  • Automation for configuring dependencies

Long term

  • Command dependency management and composition
  • Assistant like behaviour (hey bow rebuild then redeploy then check and loadTest tomorrow)

License

MIT License

Copyright (c) 2019 Oswaldo C. Dantas Jr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

hey's People

Contributors

oswaldo avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

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.