diff --git a/.codebeatsettings b/.codebeatsettings new file mode 100644 index 0000000..fbca893 --- /dev/null +++ b/.codebeatsettings @@ -0,0 +1,9 @@ +{ + "GOLANG": { + "ABC": [15, 25, 50, 70], + "LOC": [30, 45, 70, 100], + "TOO_MANY_IVARS": [12, 16, 20, 24], + "TOO_MANY_FUNCTIONS": [50, 70, 90, 120], + "TOTAL_LOC": [500, 750, 1000, 2000] + } +} diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..45abf3d --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,42 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, and in the interest of +fostering an open and welcoming community, we pledge to respect all people who +contribute through reporting issues, posting feature requests, updating +documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free +experience for everyone, regardless of level of experience, gender, gender +identity and expression, sexual orientation, disability, personal appearance, +body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic + addresses, without explicit permission +* Other unethical or unprofessional conduct + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +By adopting this Code of Conduct, project maintainers commit themselves to +fairly and consistently applying these principles to every aspect of managing +this project. Project maintainers who do not follow or enforce the Code of +Conduct may be permanently removed from the project team. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting a project maintainer at `conduct@essentialkaos.com`. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. Maintainers are +obligated to maintain confidentiality with regard to the reporter of an +incident. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..d7da3fb --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,19 @@ +# Contributing Guidelines + +**IMPORTANT! Contribute your code only if you have an excellent understanding of project idea and all existing code base. Otherwise, a nicely formatted issue will be more helpful to us.** + +### Issues + +1. Provide product version where the problem was found; +2. Provide info about your environment; +3. Provide detailed info about your problem; +4. Provide steps to reproduce the problem; +5. Provide actual and expected results. + +### Code + +1. Check your code **before** creating pull request; +2. If tests are present in a project, add tests for your code; +3. Add inline documentation for your code; +4. Apply code style used throughout the project; +5. Create your pull request to `develop` branch (_pull requests to other branches are not allowed_). diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..0e1478a --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,53 @@ +_Before opening an issue, search for similar bug reports or feature requests on GitHub Issues. If yes, please add a_ 👍 _reaction to the existing issue. If no similar issue can be found, fill out either the "Bug Report" or the "Feature Request" section below. Erase the other section and everything on and above this line._ + +### Bug report + +**System info:** + +* **Version used (`uc -v`):** +* **OS (e.g. from `/etc/*-release`):** +* **Kernel (`uname -a`):** +* **Install tools:** + +**Steps to reproduce:** + +1. [First Step] +2. [Second Step] +3. [and so on...] + +**Expected behavior:** + +[What you expected to happen] + +**Actual behavior:** + +[What actually happened] + +**Additional info:** + +[Include gist of relevant config, logs, etc.] + +Please run those if possible and link them from a [gist](http://gist.github.com). + +--- + +### Feature Request + +Opening a feature request kicks off a discussion. Requests may be closed if we're not actively planning to work on them. + +**Proposal:** + +[Description of the feature] + +**Current behavior:** + +[What currently happens] + +**Desired behavior:** + +[What you would like to happen] + +**Use case:** + +[Why is this important (helps with prioritizing requests)] + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..e7814b8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ +### What did you implement: + +Closes #XXXXX + +### How did you implement it: + +... + +### How can we verify it: + +... + +### TODO's: + +- [ ] Write tests +- [ ] Write documentation +- [ ] Check that there aren't other open pull requests for the same issue/feature +- [ ] Format your source code by `make fmt` +- [ ] Provide verification config / commands +- [ ] Enable "Allow edits from maintainers" for this PR +- [ ] Update the messages below + +**Is this ready for review?:** No +**Is it a breaking change?:** No diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..78ce5b4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,37 @@ +language: go + +go: + - 1.11.x + - 1.12.x + - 1.13.x + - tip + +os: + - linux + +services: + - docker + +branches: + only: + - master + - develop + +env: + global: + - IMAGE=essentialkaos/perfecto:centos7 + +jobs: + fast_finish: true + allow_failures: + - go: tip + +before_install: + - docker pull "$IMAGE" + - wget https://kaos.sh/perfecto/perfecto-docker + - chmod +x perfecto-docker + - make deps + +script: + - make all + - ./perfecto-docker common/uc.spec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..74f09f3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,270 @@ +Essential Kaos Open Source License + +Version: 1.0 — May 10, 2013. + +Please read this License Agreement carefully before downloading this software. +By downloading or using this software, you are agreeing to be bound by the +terms of this License. If you do not or cannot agree to the terms of this +License, please do not download or use the software. + +This License Agreement (hereinafter — the "License") defines the terms and +conditions of use of the Source and Object forms of the products produced by +the Essential Kaos Ltd. Company that are publicly available to any third +parties. + +This license extends and is applicable to any Source and Object form of the +product of the Essential Kaos Ltd. Company (hereinafter — the "Licensor"), +which are publicly available (open source) for download by any third party +(hereinafter — the "Licensee") by the decision of the Licensor. + +1. TERMS USED IN THE LICENSE + +For the purposes of this License the following terms are used in the following +meaning: + +1.1 Product — any result of intellectual activity, produced by the +implementation of the Source and/or Object form, in particular, but not +limited to, software (computer programs), audio and video records, images, +texts, etc. + +1.2 Source form of the product — the form, preferred for making modifications +to the Product, including, but not limited to, source code, source file +documentation, configuration and installation files, etc., initially provided +by the Licensor. + +1.3 Object form of the product — the result of automatic (computer, hardware +and technical) transformation or translation of the Source form of the Product, +including but not limited to, source code compiled into object code, generated +documentation, and other kinds of media files (resources), initially provided +by the Licensor. + +1.4 Licensor — the Essential Kaos company, holding the exclusive (property) +rights to collectively all Source and/or Object forms of products, published +on the official website of Licensor, and to each of them individually. + +1.5 Licensee — any individual, sole proprietorship, legal entity or other +entity legally capable in accordance with the provisions of the applicable +law, who downloads and uses the Source and/or Object form of the product. + +1.6 Official Website of the Licensor — web site located on the Internet under +the essentialkaos.com domain name (domain address). + +1.7 Modification of the Source or Object form of the Product — any addition, +deletion, alteration of Source or Object form of the Product, the combination +of source code with any other elements, etc. + +The License may use terms not defined in this section. In these cases, the +terms shall be interpreted in accordance with the text and the context of this +License. In the absence of a clear interpretation of the term in the text of +the License, the parties shall rely upon, firstly, the interpretations used +on the Official Website of the Licensor, and secondly, the provisions of +applicable law. + +2. VALIDITY OF THE LICENSE + +2.1 Full awareness of the conditions and provisions of this License is an +indispensable condition for downloading and using the Source and/or Object +form of the Product. + +2.2 The download of the Source and/or Object form of the Product by the +Licensee to its software and hardware device (with or without the use of +their software and hardware devices) means the Licensee is fully aware of, +accepts and agrees to, obligations to comply with and carry out the terms and +conditions of this License. In case of disagreement with certain terms and +conditions herein and/or inability to carry them out the Licensee must +withdraw from the download and use of the Source and/or Object form of the +Products. + +2.3 This License is effective upon posting on the Official Website of the +Licensor, subject to paragraph 1.4. of this License. + +2.4 This License applies to Source and/or Object form of the Products, +downloaded by the Licensee prior to publication of the License on the +Official Website of the Licensor. + +2.5 This License is valid for an indefinite period of time and shall cease +to be valid on its annulment by the Licensor. + +2.6 The Licensor has the right to change the text of the License at his sole +discretion. In case of such changes to the License text, they come into force +from the moment of publication of the new edition of the Lcense on the official +Website of the Licensor, unless otherwise defined at the publication. + +2.7 The Licensee undertakes to monitor the changes in the provisions of this +License, and bears the responsibility and risk of the potential negative +consequences resulting from non-compliance with this obligation. + +2.8 If the Licensee does not agree with the changes in the text of the License +and/or fails to carry out the terms of the new License edition, the Licensee +must withdraw from downloading and stop using the Source and/or Object form of +the Product. Otherwise, the Licensee’s continued use of the Source and/or +Object form of the Product means the Licensee agrees to the terms of the new +License edition and is capable of fully complying with them. + +2.9 The Licensor shall have the right at any time to unilaterally terminate +this License. Upon termination of this License, the Licensee is obliged to +cease all use of the Source and/or Object form of the Product. + +2.10 The current version of the License can be permanently found on the +official Website of the Licensor at: http://essentialkaos.com/ekol. + +3. PERMITTED USE + +The basic principle of download and use of the Source and/or Object form of the +Product is the use of the Source and/or Object form of the Product exclusively +for personal (internal, intra-corporate) purposes. + +The Licensor hereby gives any Licensee, regardless of location and country of +residence the right to download at no charge (for free) the Source and/or +Object form of the Product and use it under a simple (non-exclusive) license +in the following ways, and in the following amounts: + +3.1 Use of the Source and/or Object form of the Product by any means and for +any purposes (both non-commercial and commercial), not prohibited by applicable +law, solely for the personal benefit, subject to the limitations set out in +this License, including but not limited to, reproduction demonstration, +implementation of the Source and/or Object form of the Product. + +3.2 The modification of the Source and/or Object form of the Product and the +use of modified Source and/or Object form solely for the Licensee’s personal +(commercial or non-commercial) purposes. In the event that the modification of +the Source and/or Object form of the Product requires the consent of a third +party (including the cases of using the objects of the person in question for +modifying the Source and/or Object form of the Product), the Licensee must +independently obtain such consent from the party. + +3.3 The inclusion (incorporation) of the Source and/or Object form of the +Product into a larger product, preserving the validity of terms of this +License with respect to the Source and/or Object form of the Product, +incorporated in the larger product. The Licensee shall ensure that this +License is enclosed to each of the Source and/or Object form of the Product +that is included in the larger product with the obligatory indication of the +name of Licensor - Essential Kaos Ltd. Company. The Licensor shall also ensure +the binding power of this License in the larger product, into which the Source +and/or Object form of the Product is included. + +3.4 The right to distribute to third parties the Source and/or Object forms of +the Product on a non-profit (free, no-charge) basis. + +This License does not grant Licensee any rights in any part to use the +trademarks, logos, commercial symbols, service marks owned by the Licensor on +legal grounds and in accordance with the provisions of applicable law, except +when otherwise stipulated by the Licensor. + +4. RESTRICTIONS AND LIMITATIONS + +The licensor is constantly striving to improve and enhance the quality of the +Source and Object forms for their most optimal and productive use by the +Licensee. + +In connection with the aforesaid, in order to maintain the quality of the +Source and Object forms of the product and to prevent it from decreasing the +following requirements and restrictions are applied when downloading and using +the Source and Object forms of the product: + +4.1 It is prohibited to distribute to third parties the modified Source and/or +Object forms of the product in any ways and in any volume, including both on +commercial (paid, reimbursable) and non-commercial (free, no-charge) basis. In +some cases, determined at the discretion and by the decision of the Licensor, +the Licensee shall be entitled to distribute the Source and/or Object forms of +the products, but only with the Licensor’s written permission. + +4.2 It is prohibited to distribute to third parties the Source and/or Object +forms of the product on a commercial (paid, reimbursable) basis. + +5. WARRANTY DISCLAIMER + +5.1 The Licensor is committed to providing the highest quality of the Source +and Object forms of product, constantly improving them, and to the possible +extent eliminating various errors, malfunctions and defects that occur when +downloading and using the Source and Object forms of the Product. + +5.2 The Source and Object forms of the product are available to Licensee on an +"as is" basis, without any guarantees of suitability of the Source or Object +form for a particular purpose, or for the general use of the Source or Object +form of the product. + +5.3 The Licensor disclaims all warranties and obligations to ensure the +absence of any errors, faults, defects, etc., arising when downloading and +using the Source and Object forms of the product, as well as modifications of +the Source and Object forms of the product and/or using the modified Source +and Object forms of the product. + +5.4 Nothing in this License shall act as a guarantee or obligation of the +Licensor to ensure uninterrupted or error-free operation of the Source and/or +Object forms of the product. In connection therewith, the Licensor shall be +exempt from any liability for any errors, malfunctions, defects, etc., +occurring during the download and use of the Source and Object forms of +product, as well as modifications of the Source and Object forms of product +and/or the use of the modified Source and Object forms of the product. + +5.5 The Licensor does not assume any obligation to eliminate errors, +malfunctions and defects, identified by the Licensee when downloading and using +the Source and Object forms of the product, as well as modifications of the +Source and Object forms of the product and/or using the modified Source and +Object forms of the product. + +5.6 Source and/or Object forms of the product are available for download from +the official Website of the Licensor in the condition, in which they are at +present. + +5.7 The Licensee hereby confirms that he understands and accepts all risks and +adverse consequences associated with downloading and using the Source and/or +Object forms of the product, as well as modifying the Source and/or Object +forms of the product and/or using the modified Source and/or Object forms of +the product, including, but not limited to, the loss of any data, any +malfunction or damage to the software and hardware of the Licensee. + +6. LIMITATION OF LIABILITY + +6.1 The Licensor shall not be liable for incidental, direct or consequential +loss (damage, lost profits, etc.) incurred by third parties as a result of the +implementation and execution of this License. + +6.2 The Licensor shall not be liable for any failure or temporary +unavailability of the download and use of the Object or Source form of the +product. +6.3 The Licensor shall not be liable for any tort of Licensee, the Licensee's +breach of warranty and violation of civil and constitutional rights of third +parties. + +6.4 In any case, if the applicable law defines the necessity for the Licensor +to bear responsibility for the Licensee under this License, the Licensor's +liability is limited to the amount of 100 USD. + +7. INTELLECTUAL PROPERTY RIGHTS TO THE SOURCE AND OBJECT FORMS OF THE PRODUCT + +The Source and Object forms of the product have the potential and real value +for the implementation of activities by individuals and legal entities. + +7.1 The Licensor hereby confirms that he has the exclusive (property) rights to +collectively all Source and/or Object forms of the product, available for +download on the official Website of the Licensor, and to each of them +individually. + +7.2 The Licensor acknowledges that the placement of the Source and Object forms +of the product on the website for download and use does not infringe the +intellectual property rights of third parties. The exclusive rights of the +Licensor to the Source and/or Object forms of the product are supported by the +relevant permissions and consents of, or written agreements with, authors of +the Source and Object forms of the product. + +7.3 This License does not mean alienation to any third party, including the +Licensee, of the exclusive (property) rights of the Licensor to the Source or +Object forms of the product. The exclusive (property) rights to the Source or +Object forms of the product are fully retained by the Licensor. + +8. DISPUTE RESOLUTION + +8.1 Any disputes arising from the execution of this License and downloading and +using the Source and Object forms of the product, as well as modifying the +Source and Object forms of the product and/or using the modified Source and +Object forms of the product, shall be settled in the court at the Licensor’s +location. + +8.2 If the court recognizes any provision of this License as invalid, the rest +of this License shall remain unchanged, and the invalid provision shall be +amended in accordance with applicable law. + +8.3 Conditions not covered by this License shall be settled in accordance with +the law, applicable in the country of the Licensor’s registration. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8689fc9 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +################################################################################ + +# This Makefile generated by GoMakeGen 1.3.0 using next command: +# gomakegen . +# +# More info: https://kaos.sh/gomakegen + +################################################################################ + +.DEFAULT_GOAL := help +.PHONY = fmt vet all clean git-config deps help + +################################################################################ + +all: uc ## Build all binaries + +uc: ## Build uc binary + go build uc.go + +install: ## Install all binaries + cp uc /usr/bin/uc + +uninstall: ## Uninstall all binaries + rm -f /usr/bin/uc + +git-config: ## Configure git redirects for stable import path services + git config --global http.https://pkg.re.followRedirects true + +deps: git-config ## Download dependencies + go get -d -v pkg.re/essentialkaos/ek.v11 + +fmt: ## Format source code with gofmt + find . -name "*.go" -exec gofmt -s -w {} \; + +vet: ## Runs go vet over sources + go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... + +clean: ## Remove generated files + rm -f uc + +help: ## Show this info + @echo -e '\n\033[1mSupported targets:\033[0m\n' + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-12s\033[0m %s\n", $$1, $$2}' + @echo -e '' + @echo -e '\033[90mGenerated by GoMakeGen 1.3.0\033[0m\n' + +################################################################################ diff --git a/README.md b/README.md index a7f718b..687964c 100644 --- a/README.md +++ b/README.md @@ -1 +1,116 @@ -# uc +
+ + + +Usage demo • Installation • Command-line completion • Usage • Contributing • License
+ +`uc` is a simple utility for counting unique lines. + +### Usage demo + +[![demo](https://gh.kaos.st/uc-001.gif)](#usage-demo) + +### Installation + +#### From sources + +Before the initial install allows git to use redirects for [pkg.re](https://github.com/essentialkaos/pkgre) service (_reason why you should do this described [here](https://github.com/essentialkaos/pkgre#git-support)_): + +``` +git config --global http.https://pkg.re.followRedirects true +``` + +To build the `uc` from scratch, make sure you have a working Go 1.11+ workspace (_[instructions](https://golang.org/doc/install)_), then: + +``` +go get github.com/essentialkaos/uc +``` + +If you want to update `uc` to latest stable release, do: + +``` +go get -u github.com/essentialkaos/uc +``` + +#### From ESSENTIAL KAOS Public repo for RHEL6/CentOS6 + +``` +[sudo] yum install -y https://yum.kaos.st/kaos-repo-latest.el6.noarch.rpm +[sudo] yum install uc +``` + + +#### From ESSENTIAL KAOS Public repo for RHEL7/CentOS7 + +``` +[sudo] yum install -y https://yum.kaos.st/kaos-repo-latest.el7.noarch.rpm +[sudo] yum install uc +``` + +#### Prebuilt binaries + +You can download prebuilt binaries for Linux from [EK Apps Repository](https://apps.kaos.st/uc/latest). + +To install the latest prebuilt version, do: + +```bash +bash <(curl -fsSL https://apps.kaos.st/get) uc +``` + +### Command-line completion + +You can generate completion for `bash`, `zsh` or `fish` shell. + +Bash: +``` +[sudo] uc --completion=bash 1> /etc/bash_completion.d/uc +``` + + +ZSH: +``` +[sudo] uc --completion=zsh 1> /usr/share/zsh/site-functions/uc +``` + + +Fish: +``` +[sudo] uc --completion=fish 1> /usr/share/fish/vendor_completions.d/uc.fish +``` + +### Usage + +``` +Usage: uc {options} file + +Options + + --no-progress, -np Disable progress output + --no-color, -nc Disable colors in output + --help, -h Show this help message + --version, -v Show version + +Examples + + uc file.txt + Count unique lines in file.txt + + cat file.txt | uc - + Count unique lines in stdin data + +``` + +### Contributing + +Before contributing to this project please read our [Contributing Guidelines](https://github.com/essentialkaos/contributing-guidelines#contributing-guidelines). + +### License + +[EKOL](https://essentialkaos.com/ekol) + + \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..f42c71e --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,36 @@ +# Security Policies and Procedures + +This document outlines security procedures and general policies for all +ESSENTIAL KAOS projects. + + * [Reporting a Bug](#reporting-a-bug) + * [Disclosure Policy](#disclosure-policy) + +## Reporting a Bug + +The ESSENTIAL KAOS team and community take all security bugs in our projects +very seriously. Thank you for improving the security of our project. We +appreciate your efforts and responsible disclosure and will make every effort +to acknowledge your contributions. + +Report security bugs by emailing our security team at security@essentialkaos.com. + +The security team will acknowledge your email within 48 hours and will send a +more detailed response within 48 hours, indicating the next steps in handling +your report. After the initial reply to your report, the security team will +endeavor to keep you informed of the progress towards a fix and full +announcement, and may ask for additional information or guidance. + +Report security bugs in third-party dependencies to the person or team +maintaining the dependencies. + +## Disclosure Policy + +When the security team receives a security bug report, they will assign it to a +primary handler. This person will coordinate the fix and release process, +involving the following steps: + + * Confirm the problem and determine the affected versions; + * Audit code to find any similar potential problems; + * Prepare fixes for all releases still under maintenance. These fixes will be + released as fast as possible. diff --git a/common/uc.spec b/common/uc.spec new file mode 100644 index 0000000..ca1bc27 --- /dev/null +++ b/common/uc.spec @@ -0,0 +1,61 @@ +################################################################################ + +# rpmbuilder:relative-pack true + +################################################################################ + +%define debug_package %{nil} + +################################################################################ + +Summary: Simple utility for counting unique lines +Name: uc +Version: 0.0.1 +Release: 0%{?dist} +Group: Applications/System +License: EKOL +URL: https://kaos.sh/uc + +Source0: https://source.kaos.st/%{name}/%{name}-%{version}.tar.bz2 + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) + +BuildRequires: golang >= 1.11 + +Provides: %{name} = %{version}-%{release} + +################################################################################ + +%description +Simple utility for counting unique lines. + +################################################################################ + +%prep +%setup -q + +%build +export GOPATH=$(pwd) +go build src/github.com/essentialkaos/%{name}/%{name}.go + +%install +rm -rf %{buildroot} + +install -dm 755 %{buildroot}%{_bindir} +install -pm 755 %{name} %{buildroot}%{_bindir}/ + +%clean +rm -rf %{buildroot} + +################################################################################ + +%files +%defattr(-,root,root,-) +%doc LICENSE.EN LICENSE.RU +%{_bindir}/%{name} + +################################################################################ + +%changelog +* Thu Jan 30 2020 Anton Novojilov