Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 7eadb36

Browse files
author
Aleksi Salmela
committed
Merge branch 'master' of https://github.com/tmc-cli/tmc-cli into redo-multi-login-support-aleksi
2 parents 7129c3a + 861b53f commit 7eadb36

File tree

21 files changed

+924
-136
lines changed

21 files changed

+924
-136
lines changed

HACKING.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

HISTORY.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ If for some reason the alias was not added to your .bashrc or your shell of choi
4242

4343
If you are using Windows and you downloaded the .jar file, you must use tmc-cli directly with Java like so: `java -jar [path_to_tmc-cli.jar]`. In the following examples, replace `tmc` with this command. (note: you must have set Java on your system `%PATH%`. For more information, see [this Java help page](https://www.java.com/en/download/help/path.xml).)
4444

45-
Tip: On Windows, use `doskey tmc="java - jar [path_to_tmc-cli.jar] $@"` to get a convenient alias
45+
Tip: On Windows, use `doskey tmc="java - jar [path_to_tmc-cli.jar] $@"` to create a convenient alias.
4646

4747
Now that you've installed tmc-cli, you can view all available commands by running tmc without arguments or with `tmc --help`. You can also view all available options for commands by running them with the `--help` switch, for example `tmc courses --help`.
4848

49+
##Manual
50+
51+
The Unix man page for tmc-cli is located in docs/tmc.1 in this repository. To view it, open it with `man -l tmc.1`.
52+
53+
The man page is generated from docs/MANUAL.md using [md2man](https://github.com/sunaku/md2man).
54+
55+
For system administrators/packagers: To make the man page available for all users, move it to /usr/share/man/man1 - then it can be displayed with `man tmc`.
56+
4957
##Logging in
5058

51-
Once installation is complete, you can log in using `tmc login`. This saves your TMC login information to a configuration file in ~/.config/tmc-cli/ (or %LOCALAPPDATA% on Windows) - you will only have to log in once.
59+
Once installation is complete, you can log in using `tmc login`. This saves your TMC login information to a configuration file in ~/.config/tmc-cli/ (or %APPDATA% on Windows) - you will only have to log in once.
5260
```
5361
~ $ tmc login
5462
server address:

docs/HACKING.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Architecture and Hacking the tmc-cli
2+
====================================
3+
4+
## Requirements for developing tmc-cli
5+
* jdk 7
6+
* linux bash (mac's bash won't work)
7+
8+
9+
## Building tmc-cli
10+
To build tmc-cli run the appropriate Maven command.
11+
12+
$ git clone https://github.com/tmc-cli/tmc-cli.git
13+
$ mvn clean install
14+
15+
## Architecture
16+
17+
Program architecture is based on command design pattern. The program runs only a single command
18+
on each program execution.
19+
20+
Conceptually, there are three main parts in the program; the launch code, backend related code
21+
and the commands. The commands are gathered into their own package. In addition, there are utility
22+
classes in order to take care of user input/output and file handling.
23+
24+
The tmc-cli itself is mostly just an command line interface for the backend libraries.
25+
All the heavy lifting is done by [tmc-core](https://github.com/testmycode/tmc-core) and
26+
[tmc-langs](https://github.com/testmycode/tmc-langs) libraries. The tmc-cli also requires the
27+
server-side component of TestMyCode aka. [tmc-server](https://github.com/testmycode/tmc-server).
28+
29+
### Important classes
30+
31+
The `CliContext` object contains some cached data and singleton objects that are commonly used
32+
by utility classes and commands. Most importantly it has the `Io` object which is responsible
33+
for printing messages for the user and helping with other user interactions.
34+
35+
The `WorkDir` object handles most of the directory path handling. And it's used by most
36+
commands to parse the exercise arguments.
37+
38+
The `TmcUtil` class has wraps all tmc-cores functions into nicer interfac.
39+
40+
## Creating new commands
41+
42+
Every command must have `@Command` annotation and it's highly recommended to extend the
43+
AbstractCommand class. Note that the `@Command` annotation is used for creating help messages
44+
and its 'name' field is used as the sub-command name in terminal.
45+
46+
Please create all new commands inside the `command` package.
47+
48+
```java
49+
@Command(name = "command-name", desc = "Command description goes here")
50+
public class ExampleCommand extends AbstractCommand {
51+
@Override
52+
public void getOptions(Options options) {
53+
options.addOption("l", "long-option", false, "This will be seen in the help message.");
54+
// ...
55+
}
56+
}
57+
```
58+
59+
## Logging error messages
60+
61+
In case of failure, please print debug info in the error log by using slf4j logger and print some
62+
useful error messages to user with `ctx.getIo().println(' ... ');`. Ctx context object is
63+
passed into most of the code in tmc-cli and you can use it to interact with the user.
64+
65+
## Unit testing
66+
67+
If you create a new command, please use integration tests only. If you want to verify that a command
68+
or a utility class has printed text into the terminal, use `io.assertContains()` method. This custom
69+
assert method prints easily understandable error messages when it fails and doesn't require much code.
70+
71+
```java
72+
@RunWith(PowerMockRunner.class)
73+
@PrepareForTest(TmcUtil.class)
74+
public class ExampleCommandTest {
75+
76+
private Application app;
77+
private CliContext ctx;
78+
private TestIo io;
79+
private TmcCore mockCore;
80+
private WorkDir workDir;
81+
private Path tempDir;
82+
83+
@Before
84+
public void setUp() {
85+
// redirect the course related files into tmp
86+
tempDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("exampleTest");
87+
workDir = new WorkDir(tempDir);
88+
89+
io = new TestIo();
90+
mockCore = mock(TmcCore.class);// make sure that nothing is leaked to tmcCore
91+
ctx = new CliContext(io, workDir, mockCore);
92+
app = new Application(ctx);
93+
94+
mockStatic(TmcUtil.class);
95+
}
96+
97+
@After
98+
public void tearDown() {
99+
try {
100+
FileUtils.deleteDirectory(tempDir.toFile());
101+
} catch (Exception e) { }
102+
}
103+
104+
@Test
105+
public void exampleSucceedsWhenGivenValidCourse() {
106+
course = ...;
107+
when(TmcUtil.findCourse(eq(ctx), eq("course1"))).thenReturn(course);
108+
109+
String[] args = {"example course1"};
110+
app.run(args);
111+
io.assertContains("something went right");
112+
}
113+
}
114+
```
115+
116+
If you are doing tests for any other class, simply create normal unit tests
117+
that don't depend on any command.

docs/HISTORY.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
0.6.3 / 28.6.2016
2+
=================
3+
4+
* Release for demo
5+
* Bug fixes and polish
6+
7+
0.6.1 / 23.6.2016
8+
=================
9+
10+
* Feedback can be sent
11+
* download -command doesn't download locked exercises (by default)
12+
* Bug fixes
13+
* Known issues:
14+
* External programs such as text editor and pager cannot be opened on Windows, with the exception of the default internet browser
15+
* On some systems, progress bars print ? instead of the intended character
16+
17+
0.6.0 / 22.6.2016
18+
=================
19+
20+
* exercises -command has an -a option
21+
* Valgrind errors are now printed
22+
* The colours for progress bars and test results can be changed
23+
* All locally tested exercises can be submitted with submit -c
24+
25+
0.5.2 / 21.6.2016
26+
=================
27+
28+
* Supports custom colors in progress bars and submit command
29+
* Info command works without arguments
30+
* Download only exercises that aren't completed
31+
* Info and exercises commands won't need internet connection any more
32+
* Ask user if they want to put message to paste
33+
* Login command asks now always the server
34+
* Properties command prints now the keys in sorted order
35+
36+
0.5.1 / 17.6.2016
37+
=================
38+
39+
* Auto-complete file paths
40+
* Internal properties can be set with prop command
41+
* Progress bar looks little bit nicer
42+
43+
0.5.0 / 16.6.2016
44+
=================
45+
46+
* Improved unit testing
47+
* Course info command created
48+
* Logout command created
49+
50+
0.4.2 / 9.6.2016
51+
================
52+
53+
* Fixed a tmc-langs related issue where the submitted exercise wouldn't compile on server
54+
55+
0.3.0 / 23.5.2016
56+
=================
57+
58+
* Command created for code pastes
59+
* Exercises can be submitted
60+
* Tests can be run locally
61+
* Submission results are printed nicely
62+
* Bug fixes
63+
64+
0.2.0 / 23.5.2016
65+
=================
66+
67+
* Allow user to list courses.
68+
* Support listing excersices.
69+
* Create help command
70+
* Return the version numbrer with -v flag
71+
72+
0.1.0 / 16.5.2016
73+
=================
74+
75+
* Initial release

0 commit comments

Comments
 (0)