-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from 2m/cli-project
Refactor CLI to a separate project
- Loading branch information
Showing
11 changed files
with
187 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
rule = SortImports | ||
SortImports.blocks = [ | ||
"java.", | ||
"scala.", | ||
"akka.", | ||
"*", | ||
"lt.dvim.authors.", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Prepare the test repo | ||
|
||
This project uses a prepared Git repository when running some of the tests. | ||
The test git repository is registered as a git submodule. | ||
You will need to initialize and update the submodule before running the tests: | ||
|
||
```sh | ||
git submodule init | ||
git submodule update | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2016 Martynas Mickevičius | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package lt.dvim.authors | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.duration._ | ||
|
||
import org.rogach.scallop._ | ||
|
||
object AuthorsCli { | ||
import ScallopOpts._ | ||
|
||
class Config(args: Seq[String]) extends ScallopConf(args) { | ||
banner("""|Fetches a summary of authors that contributed to a project between two points in git history. | ||
|Usage: authors [-p <path>] [-r <repo>] <from-ref> <to-ref> | ||
| | ||
|From and to git references can be: | ||
| * commit short hash | ||
| * tag name | ||
| * HEAD | ||
| | ||
|If <path> is not specified, current directory "." is used by default. | ||
| | ||
|If <repo> is not specified, it is parsed from the origin url. | ||
""".stripMargin) | ||
|
||
val path = opt[String](default = Some("."), descr = "Path to the local project directory") | ||
val repo = opt[String](default = None, descr = "org/repo of the project") | ||
val timeout = opt[FiniteDuration](default = Some(30.seconds), descr = "Timeout for the command") | ||
val fromRef = trailArg[String]() | ||
val toRef = trailArg[String]() | ||
|
||
verify() | ||
} | ||
|
||
def main(args: Array[String]) = { | ||
val config = new Config(args.toIndexedSeq) | ||
|
||
val future = | ||
Authors.summary( | ||
config.repo.toOption, | ||
config.fromRef.toOption.get, | ||
config.toRef.toOption.get, | ||
config.path.toOption.get | ||
) | ||
|
||
println(Await.result(future, config.timeout.toOption.get)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2016 Martynas Mickevičius | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package lt.dvim.authors | ||
|
||
import scala.concurrent.duration.Duration | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
import org.rogach.scallop._ | ||
|
||
object ScallopOpts { | ||
implicit val finiteDurationConverter = singleArgConverter[FiniteDuration] { arg => | ||
Duration(arg) match { | ||
case d: FiniteDuration => d | ||
case d => throw new IllegalArgumentException(s"'$d' is not a FiniteDuration.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2016 Martynas Mickevičius | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package lt.dvim.authors | ||
|
||
import org.scalatest.wordspec.AnyWordSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class ParseRepoSpec extends AnyWordSpec with Matchers { | ||
|
||
"repo parser" must { | ||
"parse https url" in { | ||
Authors.parseRepo("https://github.com/2m/authors.git") shouldBe "2m/authors" | ||
} | ||
|
||
"parse ssh url" in { | ||
Authors.parseRepo("git@github.com:2m/authors.git") shouldBe "2m/authors" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters