Giter Club home page Giter Club logo

ymlio's Introduction

Ymlio

Ymlio is a cli tool that splits and combines yaml files and deals with multiple special cases (See below):

Installation

Installation using golang

1. Install golang on your system.

see https://go.dev/doc/install

2. Install ymlio using:

go install github.com/mekkyz/ymlio@latest

Installation without golang

1. Get the binary

The ymlio tool is a binary file and needs no installation. The only prerequisite is that you have access as an administrator on the OS you are installing it on. Download the latest release for your OS from here

2. Make it an executable and run it.

On Linux, make this file executable by doing: chmod u+x ymlio.

On Windows, the file should be executable by default, i.e. do nothing.

On macOS, make this file executable by doing: chmod u+x ymlio.amd.osx or chmod u+x ymlio.arm.osx. If the there is a security pop-up when running the command, please also Allow the executable in System Preferences > Security & Privacy.

3. For Linux users

If you want to use the tool globally just copy the ymlio file to your bin folder using sudo cp ymlio /usr/local/bin/ymlio

Usage

1. Splitting

splits a multipe-file-yaml-file into single-yaml-files.

This is also capable of extracting only some files using the --only flag. It handles also other types of files (currently handles in addition to yaml also normal text files if they have the string __RAW and it can import content of other files if they have the string __IMPORT)

  • ymlio split file.yml This should split all the files in the yaml file.

  • ymlio split file.yml --only key1.yml key2.yml this should only split the specified files after the --only tag.

    • Special case: if there is only one file specified after --only -> it will export this file and also print it out to the terminal. -> Stdout Example: ymlio split file.yml --only key.yml
  • The tool also handles __RAW Tags while splitting.

    • If there is a file in the file.yml with the tag __RAW The program will handle it as plain text. This is also handled in combine
  • If the file name is - it will its content from Stdin Example: ymlio split - or ymlio split - --only key.yml

  • The tool also handles __IMPORT Tags while splitting.

    • If there is a file in the file.yml with the tag __IMPORT The program will import the content of the specified file under __IMPORT. Example:
        importtest
            __IMPORT: m1.md

    This will import the content of m1.md file. The m1.md must be in the same folder as the file.yml

  • The tool also handles anchors

2. Combining

combines single-yaml-files into a multipe-file-yaml-file

This can also handle other types of files mentioned under 1. Splitting

  • ymlio combine file1.yml file2.yml combined.yml This should combine all the files before the last argument and put them together in the last argument. The command here will combine file1.yml and file2.yml and adds them to combined.yml (If the file combined.yml not there, it will be created)

    • If the combined.yml is already there. It will be overwritten
    • If you want to append to it using the flag --extend Example: ymlio combine file1.yml file2.yml combined.yml --extend
  • The combine also handles __RAW

    • If the program detects a file with a text content (not a yaml format). It will put the tag __RAW to it.

ymlio's People

Contributors

mekkyz avatar

Stargazers

Ahmed Amer avatar

Watchers

Ahmed Amer avatar  avatar

Forkers

mehmood86

ymlio's Issues

remove binary from repo

The compiled main binary should be excluded from the repo, as it can easily be generated and just adds clutter.

Read from stdin

When using ymlio split and no filename is passed or the passed filename equals -, then the tool should read the input file from stdin.

Add Documentation

Cobra has a feature to automatically generate documentation for you. Please have a look if you can use it.

Changing how `split` command determines filenames

At present, using the split command meaningfully requires that keys in the parent YAML file have an extension i.e.

my_yaml_file.yml:
  key1: dict
  key2: str

produces a YAML file called my_yaml_file.yml. This then fails if the file is supplied from an external resource, e.g. is a valid docker-compose file.

This issue suggests a specification that changes this requirement and makes the tool more flexible. The specification is as follows:

  1. Extension .yml is automatically appended to the key that is being exported as a file. So, the following will result in files my_yaml_file1.yml and my_yaml_file2.yml.
my_yaml_file1:
  key1: dict
my_yaml_file2:
  key2: str
  1. If it is required that a given extension is used, the following format for key can be used. Following would create four files, namely my_text_file1.txt, my_file_with_no_extension, .dotfile and my_yaml_file3.yml.
./my_text_file1.txt:
./my_file_with_no_extension:
my_yaml_file3:
  key3: float
./.dotfile:
  1. The same can be extended to encode folders by using a trailing slash. The following should create two folders my_folder and my_second_folder, each containing a subfolder called subfolder.
./my_folder/:
./my_folder/subfolder/:
./my_second_folder/subfolder/:
  1. A combination of all of the above is also possible using the following notation:
./my_third_folder/my_yaml_file4:
  key4: int
./my_fourth_folder/./my_file_without_extension

A suggestion would be to implement 1, 2, and 3 first with the possibility of implementing 4 if required.

Indentation is broken when combining files

Consider the two files:

production:
  int_key: 1
  string_key: value
development:
  int_key2: 2
  string_key2: value2

running ymlio combine file1.yml file2.yml output.yml results in this:

/tmp/tmp.RJycLxVELk.yml:
  production:
  int_key: 1
  string_key: value

/tmp/tmp.ixXOqTjG5U.yml:
  development:
  int_key2: 2
  string_key2: value2

There should be an indentation.

Remove unnecessary empty lines from sources

A lot of unnecessary empty lines are present in the source files, i.e.:





ymlio/cmd/splityamlcmd.go

Lines 150 to 155 in d1392e6

// fmt.Printf("%+v\n", importData)
// fmt.Println()
// fmt.Printf("%+v\n", fileNames)
// os.Exit(1)


... and others ...

Streamlining Output Stream

At present, the tool expects that, when combining YML files, the name of the output file will be the last argument in the input string i.e. the command will be as follows:
ymlio combine A.yml B.yml AB.yml or
ymlio combine A.yml B.yml C.yml ABC.ymal
when combining files A.yml, B.yml, ... to produce AB.yml or AB....yml.

This is contrary to standard practice for CLI tools that expect the output file to be specified by using the -o/--output flag or by simply redirecting the output from stdout to a file using > or >>. This issue suggests that the tool be modified to follow the standard practice of redirecting the stdout in the short term. The implementation of a flag for output can then be done at a later stage.

Versioning in tool

It might be a good to include version as a feature in the tool i.e. implement ymlio -v command.

One can then also always include a comment: # written using ymlio vX.x in all the files that are written using the tool.

.yaml in key causes segvault during split

test2.yml:
  int_key2: 2
  string_key2: value2
test3.yaml:
  int_key: 1
  string_key: value

Running ymlio split <file.something> fails. If test3.yaml is replaced with test3.yml, then it works.

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.