mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
Use more descriptive module name instead of 'utils'
This commit is contained in:
parent
0737c3254e
commit
36a3bd2113
20 changed files with 47 additions and 57 deletions
|
@ -3,7 +3,7 @@ use std::path::{PathBuf, MAIN_SEPARATOR};
|
|||
use mlua::prelude::*;
|
||||
use tokio::fs;
|
||||
|
||||
use crate::utils::table::TableBuilder;
|
||||
use crate::lua::table::TableBuilder;
|
||||
|
||||
pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||
TableBuilder::new(lua)?
|
||||
|
|
|
@ -6,15 +6,13 @@ use console::style;
|
|||
use hyper::Server;
|
||||
use tokio::{sync::mpsc, task};
|
||||
|
||||
use crate::{
|
||||
lua::{
|
||||
net::{
|
||||
NetClient, NetClientBuilder, NetLocalExec, NetService, NetWebSocket, RequestConfig,
|
||||
ServeConfig,
|
||||
},
|
||||
task::{TaskScheduler, TaskSchedulerAsyncExt},
|
||||
use crate::lua::{
|
||||
net::{
|
||||
NetClient, NetClientBuilder, NetLocalExec, NetService, NetWebSocket, RequestConfig,
|
||||
ServeConfig,
|
||||
},
|
||||
utils::{net::get_request_user_agent_header, table::TableBuilder},
|
||||
table::TableBuilder,
|
||||
task::{TaskScheduler, TaskSchedulerAsyncExt},
|
||||
};
|
||||
|
||||
pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||
|
@ -22,7 +20,7 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
|||
// web requests and store it in the lua registry,
|
||||
// allowing us to reuse headers and internal structs
|
||||
let client = NetClientBuilder::new()
|
||||
.headers(&[("User-Agent", get_request_user_agent_header())])?
|
||||
.headers(&[("User-Agent", create_user_agent_header())])?
|
||||
.build()?;
|
||||
lua.set_named_registry_value("net.client", client)?;
|
||||
// Create the global table for net
|
||||
|
@ -35,6 +33,15 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
|||
.build_readonly()
|
||||
}
|
||||
|
||||
fn create_user_agent_header() -> String {
|
||||
let (github_owner, github_repo) = env!("CARGO_PKG_REPOSITORY")
|
||||
.strip_prefix("https://github.com/")
|
||||
.unwrap()
|
||||
.split_once('/')
|
||||
.unwrap();
|
||||
format!("{github_owner}-{github_repo}-cli")
|
||||
}
|
||||
|
||||
fn net_json_encode(_: &'static Lua, (val, pretty): (LuaValue, Option<bool>)) -> LuaResult<String> {
|
||||
if let Some(true) = pretty {
|
||||
serde_json::to_string_pretty(&val).map_err(LuaError::external)
|
||||
|
|
|
@ -10,9 +10,8 @@ use mlua::prelude::*;
|
|||
use os_str_bytes::RawOsString;
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::{
|
||||
lua::task::TaskScheduler,
|
||||
utils::{process::pipe_and_inherit_child_process_stdio, table::TableBuilder},
|
||||
use crate::lua::{
|
||||
process::pipe_and_inherit_child_process_stdio, table::TableBuilder, task::TaskScheduler,
|
||||
};
|
||||
|
||||
const PROCESS_EXIT_IMPL_LUA: &str = r#"
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
|
||||
use mlua::prelude::*;
|
||||
|
||||
use crate::utils::table::TableBuilder;
|
||||
use crate::lua::table::TableBuilder;
|
||||
|
||||
const REQUIRE_IMPL_LUA: &str = r#"
|
||||
local source = info(1, "s")
|
||||
|
|
|
@ -2,14 +2,14 @@ use blocking::unblock;
|
|||
use dialoguer::{theme::ColorfulTheme, Confirm, Input, MultiSelect, Select};
|
||||
use mlua::prelude::*;
|
||||
|
||||
use crate::{
|
||||
lua::stdio::{PromptKind, PromptOptions, PromptResult},
|
||||
utils::{
|
||||
use crate::lua::{
|
||||
stdio::{
|
||||
formatting::{
|
||||
format_style, pretty_format_multi_value, style_from_color_str, style_from_style_str,
|
||||
},
|
||||
table::TableBuilder,
|
||||
prompt::{PromptKind, PromptOptions, PromptResult},
|
||||
},
|
||||
table::TableBuilder,
|
||||
};
|
||||
|
||||
pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
use mlua::prelude::*;
|
||||
|
||||
use crate::{
|
||||
lua::{
|
||||
async_ext::LuaAsyncExt,
|
||||
task::{
|
||||
LuaThreadOrFunction, LuaThreadOrTaskReference, TaskKind, TaskReference, TaskScheduler,
|
||||
TaskSchedulerScheduleExt,
|
||||
},
|
||||
use crate::lua::{
|
||||
async_ext::LuaAsyncExt,
|
||||
table::TableBuilder,
|
||||
task::{
|
||||
LuaThreadOrFunction, LuaThreadOrTaskReference, TaskKind, TaskReference, TaskScheduler,
|
||||
TaskSchedulerScheduleExt,
|
||||
},
|
||||
utils::table::TableBuilder,
|
||||
};
|
||||
|
||||
const SPAWN_IMPL_LUA: &str = r#"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use mlua::prelude::*;
|
||||
|
||||
use crate::utils::{
|
||||
formatting::{format_label, pretty_format_multi_value},
|
||||
table::TableBuilder,
|
||||
use crate::{
|
||||
lua::stdio::formatting::{format_label, pretty_format_multi_value},
|
||||
lua::table::TableBuilder,
|
||||
};
|
||||
|
||||
pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||
|
|
|
@ -6,16 +6,15 @@ use tokio::task::LocalSet;
|
|||
|
||||
pub(crate) mod globals;
|
||||
pub(crate) mod lua;
|
||||
pub(crate) mod utils;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use crate::utils::formatting::pretty_format_luau_error;
|
||||
|
||||
pub use globals::LuneGlobal;
|
||||
pub use lua::create_lune_lua;
|
||||
|
||||
use lua::stdio::formatting::pretty_format_luau_error;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Lune {
|
||||
args: Vec<String>,
|
||||
|
|
|
@ -2,7 +2,7 @@ use async_trait::async_trait;
|
|||
use futures_util::Future;
|
||||
use mlua::prelude::*;
|
||||
|
||||
use crate::{lua::task::TaskScheduler, utils::table::TableBuilder};
|
||||
use crate::{lua::table::TableBuilder, lua::task::TaskScheduler};
|
||||
|
||||
use super::task::TaskSchedulerAsyncExt;
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ mod create;
|
|||
|
||||
pub mod async_ext;
|
||||
pub mod net;
|
||||
pub mod process;
|
||||
pub mod stdio;
|
||||
pub mod table;
|
||||
pub mod task;
|
||||
|
||||
pub use create::create as create_lune_lua;
|
||||
|
|
|
@ -13,8 +13,8 @@ use hyper_tungstenite::{is_upgrade_request as is_ws_upgrade_request, upgrade as
|
|||
use tokio::task;
|
||||
|
||||
use crate::{
|
||||
lua::table::TableBuilder,
|
||||
lua::task::{TaskScheduler, TaskSchedulerAsyncExt, TaskSchedulerScheduleExt},
|
||||
utils::table::TableBuilder,
|
||||
};
|
||||
|
||||
use super::{NetServeResponse, NetWebSocket};
|
||||
|
|
|
@ -10,7 +10,7 @@ use tokio::{
|
|||
sync::Mutex,
|
||||
};
|
||||
|
||||
use crate::utils::table::TableBuilder;
|
||||
use crate::lua::table::TableBuilder;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NetWebSocket<T> {
|
||||
|
|
|
@ -3,7 +3,8 @@ use std::process::ExitStatus;
|
|||
use mlua::prelude::*;
|
||||
use tokio::{io, process::Child, task};
|
||||
|
||||
use crate::utils::futures::AsyncTeeWriter;
|
||||
mod tee_writer;
|
||||
use tee_writer::AsyncTeeWriter;
|
||||
|
||||
pub async fn pipe_and_inherit_child_process_stdio(
|
||||
mut child: Child,
|
|
@ -1,3 +1,2 @@
|
|||
mod prompt;
|
||||
|
||||
pub use prompt::{PromptKind, PromptOptions, PromptResult};
|
||||
pub mod formatting;
|
||||
pub mod prompt;
|
||||
|
|
3
packages/lib/src/lua/table/mod.rs
Normal file
3
packages/lib/src/lua/table/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod builder;
|
||||
|
||||
pub use builder::TableBuilder;
|
|
@ -1,5 +0,0 @@
|
|||
pub mod formatting;
|
||||
pub mod futures;
|
||||
pub mod net;
|
||||
pub mod process;
|
||||
pub mod table;
|
|
@ -1,13 +0,0 @@
|
|||
pub fn get_github_owner_and_repo() -> (String, String) {
|
||||
let (github_owner, github_repo) = env!("CARGO_PKG_REPOSITORY")
|
||||
.strip_prefix("https://github.com/")
|
||||
.unwrap()
|
||||
.split_once('/')
|
||||
.unwrap();
|
||||
(github_owner.to_owned(), github_repo.to_owned())
|
||||
}
|
||||
|
||||
pub fn get_request_user_agent_header() -> String {
|
||||
let (github_owner, github_repo) = get_github_owner_and_repo();
|
||||
format!("{github_owner}-{github_repo}-cli")
|
||||
}
|
Loading…
Reference in a new issue