Skip to content

Commit

Permalink
Converted 'range' to flag instead of -y argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridha Hassoun committed Mar 13, 2017
1 parent 4f21d58 commit 6dfe068
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,4 @@ typings/
.yarn-integrity

# dotenv environment variables file
.env

# macOS
.DS_Store
.env
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ npm install --global @captainsafia/legit
-f --file <file> The file to add a header to
-u --user [user] The user/organization who holds the license
-y --year [year] The year the license is in effect.
If 'range' is used in place of a year, a date range from the first commit year
to the current year will be used.
-r --range Year range from first commit year to current year.
Takes precedence over -y/--year.
```

![Legit Demo](https://cloud.githubusercontent.com/assets/1857993/23821404/bea5dfc2-05f6-11e7-8525-7f5bd88a7829.gif)
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@ program
.option('-f --file [file]', 'The file to add a header to')
.option('-u --user [user]', 'The user/organization who holds the license')
.option('-y --year [year]', 'The year the license is in effect')
.option('-r --range', 'Year range from first commit year to current year.')
.description('Put a license in this directory')
.action(function(licenseArg) {
const cwd = process.cwd();
const fileArg = this.file;
var yearArg;
const userArg = this.user || username.sync();
var yearArg = this.year || new Date().getFullYear();

if (this.year === "range") {
if (this.range) {
var firstCommitYear = firstCommitDate.sync(cwd + '/.git').getFullYear();
var currentYear = new Date().getFullYear();
if (currentYear === firstCommitYear) {
yearArg = currentYear;
} else {
yearArg = firstCommitYear + "-" + currentYear;
}
} else {
yearArg = this.year || new Date().getFullYear();
}

const user = placeholders[licenseArg]['user'];
Expand Down

0 comments on commit 6dfe068

Please sign in to comment.