Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b707d31

Browse files
Merge branch 'clearloop:master' into master
2 parents 40a8caa + 930064f commit b707d31

File tree

17 files changed

+164
-167
lines changed

17 files changed

+164
-167
lines changed

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
**/*.rs.bk
33
Cargo.lock
44
.DS_Store
5-
.idea
5+
.idea
6+
.direnv/

‎Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ readme = './README.md'
1818
[dependencies]
1919
async-trait = "0.1.56"
2020
tokio = { version = "1.19.2", features = ["full"] }
21-
clap = { version = "3.2.10", features = ["cargo"] }
21+
clap = { version = "4", features = ["cargo"] }
2222
colored = "2.0.0"
2323
dirs = "4.0.0"
2424
env_logger = "0.9.0"

‎flake.lock

Lines changed: 6 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,40 @@
22
description = "Leet your code in command-line.";
33

44
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5-
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
65
inputs.utils.url = "github:numtide/flake-utils";
76

8-
outputs = { self, nixpkgs, rust-overlay,utils, ... }:
7+
outputs = { self, nixpkgs, utils, ... }:
98
utils.lib.eachDefaultSystem (system:
109
let
11-
pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlay ]; };
10+
pkgs = import nixpkgs { inherit system; };
11+
12+
nativeBuildInputs = with pkgs; [
13+
pkg-config
14+
];
15+
16+
buildInputs = with pkgs; [
17+
openssl
18+
dbus
19+
sqlite
20+
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
1221

13-
platform = with pkgs; makeRustPlatform {
14-
rustc = rust-bin.nightly.latest.minimal;
15-
cargo = rust-bin.nightly.latest.minimal;
16-
};
17-
package = with pkgs; platform.buildRustPackage rec {
18-
pname = "leetcode-cli";
19-
version = "0.3.10";
2022

23+
package = with pkgs; rustPlatform.buildRustPackage rec {
24+
pname = "leetcode-cli";
25+
version = "0.3.11";
2126
src = fetchCrate {
2227
inherit pname version;
23-
sha256 = "SkJLA49AXNTpiWZByII2saYLyN3bAAJTlCvhamlOEXA=";
28+
sha256 = "sha256-DHtIhiRPRGuO6Rf1d9f8r0bMOHqAaJleUvYNyPiX6mc=";
2429
};
30+
cargoSha256 = "sha256-Suk/nQ+JcoD9HO9x1lYp+p4qx0DZ9dt0p5jPz0ZQB+k=";
2531

26-
cargoSha256="xhKF4qYOTdt8iCSPY5yT8tH3l54HdkOAIS2SBGzqsdo=";
32+
inheritbuildInputsnativeBuildInputs;
2733

2834
# a nightly compiler is required unless we use this cheat code.
2935
RUSTC_BOOTSTRAP = 0;
3036

31-
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-nightly";
32-
CFG_RELEASE_CHANNEL = "ngihtly";
33-
34-
nativeBuildInputs = [
35-
pkg-config
36-
rust-bin.stable.latest.default
37-
];
38-
39-
buildInputs = [
40-
openssl
41-
dbus
42-
sqlite
43-
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
37+
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
38+
CFG_RELEASE_CHANNEL = "stable";
4439

4540
meta = with pkgs.lib; {
4641
description = "Leet your code in command-line.";
@@ -54,6 +49,28 @@
5449
{
5550
defaultPackage = package;
5651
overlay = final: prev: { leetcode-cli = package; };
52+
53+
devShell = with pkgs; mkShell {
54+
name = "shell";
55+
inherit nativeBuildInputs;
56+
57+
buildInputs = buildInputs ++ [
58+
rustc
59+
cargo
60+
rustfmt
61+
clippy
62+
rust-analyzer
63+
cargo-edit
64+
cargo-bloat
65+
cargo-audit
66+
cargo-about
67+
cargo-outdated
68+
];
69+
70+
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
71+
RUST_BACKTRACE = "full";
72+
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
73+
};
5774
}
5875
);
5976
}

‎src/cache/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Cache {
5555
}
5656

5757
pub fn update_after_ac(self, rid: i32) -> Result<(), Error> {
58-
let c = conn((&self.0.conf.storage.cache()?).to_owned());
58+
let c = conn(self.0.conf.storage.cache()?);
5959
let target = problems.filter(id.eq(rid));
6060
diesel::update(target).set(status.eq("ac")).execute(&c)?;
6161
Ok(())

‎src/cache/models.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl std::fmt::Display for VerifyResult {
290290

291291
match &self.status.status_code {
292292
10 => {
293-
if self.correct_answer {
293+
if matches!(self.result_type,Run::Test) && self.correct_answer {
294294
// Pass Tests
295295
write!(
296296
f,
@@ -305,17 +305,20 @@ impl std::fmt::Display for VerifyResult {
305305
&"\nExpected:".after_spaces(6),
306306
eca,
307307
)?
308-
} else if !self.submit.compare_result.is_empty() {
308+
} else if matches!(self.result_type, Run::Submit)
309+
&& !self.submit.compare_result.is_empty()
310+
{
311+
// only Submit execute this branch
309312
// Submit Successfully
310-
// TODO: result shoule be all 1;
313+
// TODO: result should be all 1;
311314
// Lines below are sucks...
312315
let cache = super::Cache::new().expect("cache gen failed");
313316
cache
314317
.update_after_ac(
315318
self.submit
316319
.question_id
317320
.parse()
318-
.expect("submit succcessfully, parse question_id to i32 failed"),
321+
.expect("submit successfully, parse question_id to i32 failed"),
319322
)
320323
.expect("update ac to cache failed");
321324

‎src/cli.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
flag::{Debug, Flag},
99
};
1010
use clap::{crate_name, crate_version};
11+
use log::LevelFilter;
1112

1213
/// This should be called before calling any cli method or printing any output.
1314
pub fn reset_signal_pipe_handler() {
@@ -22,7 +23,7 @@ pub fn reset_signal_pipe_handler() {
2223
}
2324
}
2425

25-
/// Get maches
26+
/// Get matches
2627
pub async fn main() -> Result<(), Error> {
2728
reset_signal_pipe_handler();
2829
let m = clap::Command::new(crate_name!())
@@ -41,10 +42,11 @@ pub async fn main() -> Result<(), Error> {
4142
.arg_required_else_help(true)
4243
.get_matches();
4344

44-
if m.contains_id("debug") {
45+
if m.get_flag("debug") {
4546
Debug::handler()?;
4647
} else {
47-
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("info"))
48+
env_logger::Builder::new()
49+
.filter_level(LevelFilter::Info)
4850
.format_timestamp(None)
4951
.init();
5052
}

‎src/cmds/data.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use super::Command;
33
use crate::{cache::Cache, helper::Digit, Error};
44
use async_trait::async_trait;
5-
use clap::{Arg, ArgMatches, Command as ClapCommand};
5+
use clap::{Arg, ArgAction,ArgMatches, Command as ClapCommand};
66
use colored::Colorize;
77

88
/// Abstract `data` command
@@ -25,23 +25,25 @@ pub struct DataCommand;
2525
#[async_trait]
2626
impl Command for DataCommand {
2727
/// `data` command usage
28-
fn usage<'a>() -> ClapCommand<'a> {
28+
fn usage() -> ClapCommand {
2929
ClapCommand::new("data")
3030
.about("Manage Cache")
3131
.visible_alias("d")
3232
.arg(
33-
Arg::with_name("delete")
33+
Arg::new("delete")
3434
.display_order(1)
3535
.short('d')
3636
.long("delete")
37-
.help("Delete cache"),
37+
.help("Delete cache")
38+
.action(ArgAction::SetTrue),
3839
)
3940
.arg(
40-
Arg::with_name("update")
41+
Arg::new("update")
4142
.display_order(2)
4243
.short('u')
4344
.long("update")
44-
.help("Update cache"),
45+
.help("Update cache")
46+
.action(ArgAction::SetTrue),
4547
)
4648
}
4749

@@ -73,13 +75,13 @@ impl Command for DataCommand {
7375
title.push_str(&"-".repeat(65));
7476

7577
let mut flags = 0;
76-
if m.contains_id("delete") {
78+
if m.get_flag("delete") {
7779
flags += 1;
7880
cache.clean()?;
7981
println!("{}", "ok!".bright_green());
8082
}
8183

82-
if m.contains_id("update") {
84+
if m.get_flag("update") {
8385
flags += 1;
8486
cache.update().await?;
8587
println!("{}", "ok!".bright_green());

‎src/cmds/edit.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@ pub struct EditCommand;
2525
#[async_trait]
2626
impl Command for EditCommand {
2727
/// `edit` usage
28-
fn usage<'a>() -> ClapCommand<'a> {
28+
fn usage() -> ClapCommand {
2929
ClapCommand::new("edit")
3030
.about("Edit question by id")
3131
.visible_alias("e")
3232
.arg(
33-
Arg::with_name("lang")
33+
Arg::new("lang")
3434
.short('l')
3535
.long("lang")
36-
.takes_value(true)
36+
.num_args(1)
3737
.help("Edit with specific language"),
3838
)
3939
.arg(
40-
Arg::with_name("id")
41-
.takes_value(true)
40+
Arg::new("id")
41+
.num_args(1)
4242
.required(true)
43+
.value_parser(clap::value_parser!(i32))
4344
.help("question id"),
4445
)
4546
}
@@ -51,7 +52,7 @@ impl Command for EditCommand {
5152
use std::io::Write;
5253
use std::path::Path;
5354

54-
let id:i32 = m.value_of("id").ok_or(Error::NoneError)?.parse()?;
55+
let id = *m.get_one::<i32>("id").ok_or(Error::NoneError)?;
5556
let cache = Cache::new()?;
5657
let problem = cache.get_problem(id)?;
5758
let mut conf = cache.to_owned().0.conf;
@@ -61,7 +62,10 @@ impl Command for EditCommand {
6162
let p_desc_comment = problem.desc_comment(&conf);
6263
// condition language
6364
if m.contains_id("lang") {
64-
conf.code.lang = m.value_of("lang").ok_or(Error::NoneError)?.to_string();
65+
conf.code.lang = m
66+
.get_one::<String>("lang")
67+
.ok_or(Error::NoneError)?
68+
.to_string();
6569
conf.sync()?;
6670
}
6771

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /