leetcode_cli/lib.rs
1//! # leetcode-cli
2//! [](https://docs.rs/leetcode-cli/)
3//! [](https://crates.io/crates/leetcode-cli)
4//! [](https://crates.io/crates/leetcode-cli)
5//! [](https://choosealicense.com/licenses/mit/)
6//!
7//! ## Installing
8//!
9//! ```sh
10//! cargo install leetcode-cli
11//! ```
12//!
13//! ## Usage
14//!
15//! **Please make sure you have logined in `leetcode.com` with `chrome`**, more info plz checkout [this](#cookies)
16//!
17//! ```sh
18//! leetcode 0.3.10
19//! May the Code be with You 👻
20//!
21//! USAGE:
22//! leetcode [FLAGS] [SUBCOMMAND]
23//!
24//! FLAGS:
25//! -d, --debug debug mode
26//! -h, --help Prints help information
27//! -V, --version Prints version information
28//!
29//! SUBCOMMANDS:
30//! data Manage Cache [aliases: d]
31//! edit Edit question by id [aliases: e]
32//! exec Submit solution [aliases: x]
33//! list List problems [aliases: l]
34//! pick Pick a problem [aliases: p]
35//! stat Show simple chart about submissions [aliases: s]
36//! test Edit question by id [aliases: t]
37//! help Prints this message or the help of the given subcommand(s)
38//! ```
39//!
40//! ## Example
41//!
42//! For example, if your config is:
43//!
44//! ```toml
45//! [code]
46//! lang = "rust"
47//! editor = "emacs"
48//! ```
49//!
50//! #### 1. <kbd>pick</kbd>
51//!
52//! ```sh
53//! leetcode pick 1
54//! ```
55//!
56//! ```sh
57//! [1] Two Sum is on the run...
58//!
59//!
60//! Given an array of integers, return indices of the two numbers such that they add up to a specific target.
61//!
62//! You may assume that each input would have exactly one solution, and you may not use the same element twice.
63//!
64//! --------------------------------------------------
65//!
66//! Example:
67//!
68//!
69//! Given nums = [2, 7, 11, 15], target = 9,
70//!
71//! Because nums[0] + nums[1] = 2 + 7 = 9,
72//! return [0, 1].
73//! ```
74//!
75//! #### 2. <kbd>edit</kbd>
76//!
77//! ```sh
78//! leetcode edit 1
79//! ```
80//!
81//! ```rust
82//! # struct Solution;
83//! impl Solution {
84//! pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
85//! use std::collections::HashMap;
86//! let mut m: HashMap<i32, i32> = HashMap::new();
87//!
88//! for (i, e) in nums.iter().enumerate() {
89//! if let Some(v) = m.get(&(target - e)) {
90//! return vec![*v, i as i32];
91//! }
92//!
93//! m.insert(*e, i as i32).unwrap_or_default();
94//! }
95//!
96//! return vec![];
97//! }
98//! }
99//! ```
100//!
101//! #### 3. <kbd>test</kbd>
102//!
103//! ```sh
104//! leetcode test 1
105//! ```
106//!
107//! ```sh
108//!
109//! Accepted Runtime: 0 ms
110//!
111//! Your input: [2,7,11,15], 9
112//! Output: [0,1]
113//! Expected: [0,1]
114//!
115//! ```
116//!
117//! #### 4. <kbd>submit</kbd>
118//!
119//! ```sh
120//! leetcode submit 1
121//! ```
122//!
123//! ```sh
124//!
125//! Success
126//!
127//! Runtime: 0 ms, faster than 100% of Rustonline submissions for Two Sum.
128//!
129//! Memory Usage: 2.4 MB, less than 100% of Rustonline submissions for Two Sum.
130//!
131//!
132//! ```
133//!
134//! ## Cookies
135//!
136//! The cookie plugin of leetcode-cil can work on OSX and [Linux][#1], **If you are on other platforms or your cookies just don't want to be catched**, you can handwrite your LeetCode Cookies to `~/.leetcode/leetcode.toml`
137//!
138//! ```toml
139//! # Make sure `leetcode.toml` file is placed at `~/.leetcode/leetcode.toml`
140//! [cookies]
141//! csrf = "..."
142//! session = "..."
143//! ```
144//!
145//! For Example, if you're using chrome to login to leetcode.com.
146//!
147//!
148//! #### Step 1
149//!
150//! Open chrome and paste the link below to the `chrome linkbar`.
151//!
152//! ```sh
153//! chrome://settings/cookies/detail?site=leetcode.com
154//! ```
155//!
156//! #### Step 2
157//!
158//! Copy the contents of `LEETCODE_SESSION` and `csrftoken`.
159//!
160//! #### Step 3
161//!
162//! Paste them to `session` and `csrf`.
163//!
164//! ```toml
165//! # Make sure `leetcode.toml` file is placed at `~/.leetcode/leetcode.toml`
166//! [cookies]
167//! csrf = "${csrftoken}"
168//! session = "${LEETCODE_SESSION}"
169//! ```
170//!
171//!
172//! ## Programmable
173//!
174//! If we want to filter leetcode questions using our own python scripts, what should we do?
175//!
176//! For example, our config is:
177//!
178//! ```toml
179//! # Make sure `leetcode.toml` file is placed at `~/.leetcode/leetcode.toml`
180//! [storage]
181//! scripts = "scripts"
182//! ```
183//!
184//! We write our python scripts:
185//!
186//! ```python
187//! # ~/.leetcode/scripts/plan1.py
188//! import json;
189//!
190//! def plan(sps, stags):
191//! ##
192//! # `print` in python is supported,
193//! # if you want to know the data structures of these two args,
194//! # just print them
195//! ##
196//! problems = json.loads(sps)
197//! tags = json.loads(stags)
198//!
199//! ret = []
200//! tm = {}
201//! for tag in tags:
202//! tm[tag["tag"]] = tag["refs"];
203//!
204//! for i in problems:
205//! if i["level"] == 1 and str(i["id"]) in tm["linked-list"]:
206//! ret.append(str(i["id"]))
207//!
208//! # return is `List[string]`
209//! return ret
210//! ```
211//!
212//! Then we can run filter as what we write now:
213//!
214//! ```sh
215//! leetcode list -p plan1
216//! ```
217//!
218//! Well done, enjoy it!
219//!
220//!
221//! ## PR
222//!
223//! PR is welcome, [here][pr] it is.
224//!
225//! ## LICENSE
226//! MIT
227//!
228//!
229//! [pr]: https://github.com/clearloop/leetcode-cli/pulls
230//! [#1]: https://github.com/clearloop/leetcode-cli/issues/1
231#[macro_use]
232extern crate log;
233#[macro_use]
234extern crate diesel;
235
236// show docs
237pub mod cache;
238pub mod cli;
239pub mod cmds;
240pub mod config;
241pub mod err;
242pub mod flag;
243pub mod helper;
244pub mod plugins;
245#[cfg(feature = "pym")]
246pub mod pym;
247
248// re-exports
249pub use cache::Cache;
250pub use config::Config;
251pub use err::{Error, Result};